Matplotlib import fails in Python Nodes

Dear all,

I am facing the same problem like in Error with Python View since 4.0.1 on a KNIME SERVER Medium (Windows Server 2016) and Anaconda 3

To simplify reporting I created a Anaconda environment (“python_plotting”) that is only containing the following packages:

(D:\data\anaconda-envs\python_plotting) C:\Users_knime>conda list
packages in environment at D:\data\anaconda-envs\python_plotting:

Name Version Build Channel
blas 1.0 mkl
ca-certificates 2020.1.1 0
certifi 2020.4.5.1 py36_0
cycler 0.10.0 py36h009560c_0
freetype 2.9.1 ha9979f8_1
icc_rt 2019.0.0 h0cc432a_1
icu 58.2 ha925a31_3
intel-openmp 2020.1 216
jedi 0.17.0 py36_0
jpeg 9b hb83a4c4_2
kiwisolver 1.2.0 py36h74a9793_0
libpng 1.6.37 h2a8f88b_0
matplotlib 3.0.3 py36hc8f65d3_0
mkl 2020.1 216
mkl-service 2.3.0 py36hb782905_0
mkl_fft 1.0.15 py36h14836fe_0
mkl_random 1.1.0 py36h675688f_0
numpy 1.18.1 py36h93ca92e_0
numpy-base 1.18.1 py36hc3f5095_1
openssl 1.1.1g he774522_0
pandas 1.0.3 py36h47e9c7a_0
parso 0.7.0 py_0
pip 20.0.2 py36_3
pyparsing 2.4.7 py_0
pyqt 5.9.2 py36h6538335_2
python 3.6.10 h9f7ef89_2
python-dateutil 2.8.1 py_0
pytz 2020.1 py_0
qt 5.9.7 vc14h73c81de_0
setuptools 46.2.0 py36_0
sip 4.19.8 py36h6538335_0
six 1.14.0 py36_0
sqlite 3.31.1 h2a8f88b_1
tornado 6.0.4 py36he774522_1
vc 14.1 h0510ff6_4
vs2015_runtime 14.16.27012 hf0eaf9b_1
wheel 0.34.2 py36_0
wincertstore 0.2 py36h7fe50ca_0
zlib 1.2.11 h62dcd97_4

importing pyplot matplotlib in terms fails in the Python Scripting Nodes, but not in the console with > > activated “python_plotting” environment:
–>
DLL load failed: %1 is not a valid Win32 application.
Traceback (most recent call last):
File “”, line 1, in
File “D:\data\anaconda-envs\py3_knime\lib\site-packages\matplotlib\pyplot.py”, line 32, in
import matplotlib.colorbar
File “D:\data\anaconda-envs\py3_knime\lib\site-packages\matplotlib\colorbar.py”, line 32, in
import matplotlib.contour as contour
File “D:\data\anaconda-envs\py3_knime\lib\site-packages\matplotlib\contour.py”, line 18, in
import matplotlib.font_manager as font_manager
File “D:\data\anaconda-envs\py3_knime\lib\site-packages\matplotlib\font_manager.py”, line 48, in
from matplotlib import afm, cbook, ft2font, rcParams, get_cachedir
ImportError: DLL load failed: %1 is not a valid Win32 application.

As I read the import of ft2font may cause these errors:

from matplotlib import ft2font
–>
DLL load failed: %1 is not a valid Win32 application.
Traceback (most recent call last):
File “”, line 1, in
ImportError: DLL load failed: %1 is not a valid Win32 application.

I already used matplotlib 3.03 as a stable version on Python 3.6.10

As I mentioned above the code can be executed in a python shell with the “python_plotting” environment described above, but not in KNIME.

It might be worth to note that the python source node does not use the right environment in the configuration view:

D:\data\anaconda-envs\python_plotting\python.exe” is the python3Command for the respective python node.

> import sys
> print(sys.version)
> print(sys.path)

result in:

3.6.10 |Anaconda, Inc.| (default, Mar 23 2020, 17:58:33) [MSC v.1916 64 bit (AMD64)]
[‘D:\KNIME-Executer\plugins\org.knime.python2_4.1.0.v201911191126\py’, ‘D:\KNIME-Executer\plugins\org.knime.dl.tensorflow_4.1.0.v201909231408\py’, ‘D:\KNIME-Executer\configuration\org.eclipse.osgi\1079\0.cp\py’, ‘D:\KNIME-Executer\plugins\org.knime.dl.keras_4.1.0.v201911110939\py’, ‘D:\KNIME-Executer\plugins\org.knime.dl.python_4.1.0.v201909231406\py’, ‘D:\KNIME-Executer\configuration\org.eclipse.osgi\1145\0.cp\py’, ‘D:\KNIME-Executer\plugins\org.knime.python2_4.1.0.v201911191126\py’, ‘D:\KNIME-Executer’, ‘D:\data\anaconda-envs\py3_knime\python36.zip’, ‘D:\data\anaconda-envs\py3_knime\DLLs’, ‘D:\data\anaconda-envs\py3_knime\lib’, ‘D:\data\anaconda-envs\py3_knime’, ‘D:\data\anaconda-envs\py3_knime\lib\site-packages’, ‘D:\data\anaconda-envs\py3_knime\lib\site-packages\win32’, ‘D:\data\anaconda-envs\py3_knime\lib\site-packages\win32\lib’, ‘D:\data\anaconda-envs\py3_knime\lib\site-packages\Pythonwin’, ‘D:\data\anaconda-envs\py3_knime\lib\site-packages\IPython\extensions’, ‘D:\KNIME-Executer\plugins\org.knime.python2.serde.flatbuffers_4.1.0.v201908271559\py\’, ‘D:\KNIME-Executer\plugins\org.knime.dl.tensorflow_4.1.0.v201909231408\py;D:\KNIME-Executer\configuration\org.eclipse.osgi\1079\0.cp\py;D:\KNIME-Executer\plugins\org.knime.dl.keras_4.1.0.v201911110939\py;D:\KNIME-Executer\plugins\org.knime.dl.python_4.1.0.v201909231406\py;D:\KNIME-Executer\configuration\org.eclipse.osgi\1145\0.cp\py’]

The standard Python3 Envirnment includes:

(D:\data\anaconda-envs\py3_knime) C:\Users_knime>conda list

packages in environment at D:\data\anaconda-envs\py3_knime:

Name Version Build Channel

arrow-cpp 0.11.1 py36h8e05e8c_1
asn1crypto 1.3.0 py36_0
attrs 19.3.0 py_0
backcall 0.1.0 py36_0
blas 1.0 mkl
ca-certificates 2020.1.1 0
cairo 1.14.12 hf171d8a_3
canmatrix 0.8 py_0 conda-forge
cchardet 2.1.6 py36hbd05846_0 conda-forge
certifi 2020.4.5.1 py36_0
cffi 1.14.0 py36h7a1dbc1_0
chardet 3.0.4 py36_1003
colorama 0.4.3 py_0
cryptography 2.8 py36h7a1dbc1_0
cycler 0.10.0 py36h009560c_0
decorator 4.4.2 py_0
freetype 2.9.1 ha9979f8_1
future 0.18.2 py36_0
gflags 2.2.2 ha925a31_0
glog 0.3.5 h6538335_1
icc_rt 2019.0.0 h0cc432a_1
icu 58.2 vc14hc45fdbb_0 [vc14] anaconda
idna 2.9 py_1
importlib_metadata 1.5.0 py36_0
intel-openmp 2020.0 166
ipython 7.1.1 py36h39e3cac_0
ipython_genutils 0.2.0 py36_0
jedi 0.13.3 py36_0
jpeg 9b vc14h4d7706e_1 [vc14] anaconda
jpype1 0.6.3 py36h79cbd7a_1001 conda-forge
jsonschema 3.2.0 py36_0
jupyter_core 4.6.3 py36_0
kiwisolver 1.1.0 py36ha925a31_0
libboost 1.67.0 hd9e427e_4
libiconv 1.15 h1df5818_7
libpng 1.6.37 h2a8f88b_0
libtiff 4.1.0 h56a325e_0
lxml 3.8.0 py36_0 anaconda
lz4-c 1.8.1.2 h2fa13f4_0
matplotlib 3.0.3 py36hc8f65d3_0
matplotlib-base 3.1.3 py36h64f37c6_0
mkl 2020.0 166
mkl-service 2.3.0 py36hb782905_0
mkl_fft 1.0.15 py36h14836fe_0
mkl_random 1.1.0 py36h675688f_0
natsort 7.0.1 py_0
nbformat 4.4.0 py36_0
numexpr 2.7.1 py36h25d0782_0
numpy 1.16.1 py36h19fb1c0_1
numpy-base 1.16.1 py36hc3f5095_1
olefile 0.46 py36_0
openssl 1.1.1g he774522_0
pandas 0.23.4 py36h830ac7b_0
parso 0.6.2 py_0
pickleshare 0.7.5 py36_0
pillow 5.3.0 py36hdc69c19_0
pip 20.0.2 py36_1
pixman 0.34.0 vc14h00fde18_1 [vc14] anaconda
prompt_toolkit 2.0.10 py_0
pyarrow 0.11.1 py36h33f27b4_0
pycparser 2.20 py_0
pygments 2.6.1 py_0
pyopenssl 19.1.0 py36_0
pyparsing 2.4.6 py_0
pyqt 5.9.2 py36h6538335_2
pyrsistent 0.16.0 py36he774522_0
pysocks 1.7.1 py36_0
python 3.6.10 h9f7ef89_1
python-dateutil 2.7.5 py36_0
python_abi 3.6 1_cp36m conda-forge
pytz 2019.3 py_0
pywin32 227 py36he774522_1
pyyaml 5.3.1 py36he774522_0
qt 5.9.7 vc14h73c81de_0
requests 2.23.0 py36_0
scipy 1.1.0 py36h29ff71c_2
seaborn 0.10.1 py_0
setuptools 46.1.3 py36_0
sip 4.19.8 py36h6538335_0
six 1.14.0 py36_0
snappy 1.1.7 vc14h2dea872_1 [vc14] anaconda
sqlite 3.31.1 he774522_0
thrift-cpp 0.11.0 h1ebf3fd_3
tk 8.6.8 hfa6e2cd_0
tornado 6.0.4 py36he774522_1
traitlets 4.3.3 py36_0
urllib3 1.25.8 py36_0
vc 14.1 h0510ff6_4
vs2015_runtime 14.16.27012 hf0eaf9b_1
wcwidth 0.1.9 py_0
wheel 0.34.2 py36_0
win_inet_pton 1.1.0 py36_0
wincertstore 0.2 py36h7fe50ca_0
xlrd 1.2.0 py36_0
xlsxwriter 1.2.8 py_0
xlwt 1.3.0 py36h1a4751e_0
xz 5.2.4 h2fa13f4_4
yaml 0.1.7 vc14h4cb57cf_1 [vc14] anaconda
zipp 2.2.0 py_0
zlib 1.2.11 vc14h1cdd9ab_1 [vc14] anaconda
zstd 1.3.7 h508b16e_0

It seems strange to me that the sys.path gives back the standard environment, not the selected one (via flow variable, corrsoponding to Need to be able to use many Anaconda environments with KNIME)

KNIME Python Integration is:

KNIME Python Integration 4.1.1.v202003021315 org.knime.features.python2.feature.group KNIME AG, Zurich, Switzerland

Any ideas ?

I would refer you to this entry and the accompanying discussion. With KNIME and Python it seems to be a lot of trial an error and you would have to start over again with a clean installation.

https://docs.knime.com/latest/python_installation_guide/index.html

2 Likes

Thank you for the response. A change in terms of creating the .bat file helped to solve the issues with the anaconda environments.

2 Likes