Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't import matplotlib, get ImportError #353

Open
1 task done
dennischen opened this issue Aug 14, 2023 · 6 comments
Open
1 task done

Can't import matplotlib, get ImportError #353

dennischen opened this issue Aug 14, 2023 · 6 comments
Labels

Comments

@dennischen
Copy link

dennischen commented Aug 14, 2023

Solution to issue cannot be found in the documentation.

  • I checked the documentation.

Issue

I am studying python + matplotlib,
Everything was ok on last Monday, but I try to re-run my case today get error.

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/dennis/.conda/envs/jplerror3/lib/python3.11/site-packages/matplotlib/__init__.py", line 129, in <module>
    from . import _api, _version, cbook, _docstring, rcsetup
  File "/home/dennis/.conda/envs/jplerror3/lib/python3.11/site-packages/matplotlib/rcsetup.py", line 27, in <module>
    from matplotlib.colors import Colormap, is_color_like
  File "/home/dennis/.conda/envs/jplerror3/lib/python3.11/site-packages/matplotlib/colors.py", line 51, in <module>
    from PIL import Image
  File "/home/dennis/.conda/envs/jplerror3/lib/python3.11/site-packages/PIL/Image.py", line 103, in <module>
    from . import _imaging as core
ImportError: libtiff.so.5: cannot open shared object file: No such file or directory

I can reporduce it by following commands in my ubuntu 20

conda create -n jplerror3 -y
conda activate jplerror3
conda install -c conda-forge python matplotlib -y
python -c "import matplotlib.pyplot as plt"

But, if I remove the -c conda-forge, it works fine

conda create -n jplerror4 -y
conda activate jplerror4
conda install python matplotlib -y
python -c "import matplotlib.pyplot as plt"

Installed packages

---From conda-forge, has error
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       2_gnu    conda-forge
brotli                    1.0.9                h166bdaf_9    conda-forge
brotli-bin                1.0.9                h166bdaf_9    conda-forge
bzip2                     1.0.8                h7f98852_4    conda-forge
ca-certificates           2023.7.22            hbcca054_0    conda-forge
certifi                   2023.7.22          pyhd8ed1ab_0    conda-forge
contourpy                 1.1.0           py311h9547e67_0    conda-forge
cycler                    0.11.0             pyhd8ed1ab_0    conda-forge
dbus                      1.13.18              hb2f20db_0
expat                     2.5.0                hcb278e6_1    conda-forge
fontconfig                2.14.2               h14ed4e7_0    conda-forge
fonttools                 4.42.0          py311h459d7ec_0    conda-forge
freetype                  2.12.1               hca18f0e_1    conda-forge
gettext                   0.21.1               h27087fc_0    conda-forge
giflib                    5.2.1                h0b41bf4_3    conda-forge
glib                      2.76.4               hfc55251_0    conda-forge
glib-tools                2.76.4               hfc55251_0    conda-forge
gst-plugins-base          1.14.1               h6a678d5_1
gstreamer                 1.14.1               h5eee18b_1
icu                       58.2              hf484d3e_1000    conda-forge
jpeg                      9e                   h0b41bf4_3    conda-forge
keyutils                  1.6.1                h166bdaf_0    conda-forge
kiwisolver                1.4.4           py311h4dd048b_1    conda-forge
krb5                      1.20.1               h81ceb04_0    conda-forge
lcms2                     2.15                 hfd0df8a_0    conda-forge
ld_impl_linux-64          2.40                 h41732ed_0    conda-forge
lerc                      4.0.0                h27087fc_0    conda-forge
libblas                   3.9.0           17_linux64_openblas    conda-forge
libbrotlicommon           1.0.9                h166bdaf_9    conda-forge
libbrotlidec              1.0.9                h166bdaf_9    conda-forge
libbrotlienc              1.0.9                h166bdaf_9    conda-forge
libcblas                  3.9.0           17_linux64_openblas    conda-forge
libclang                  10.0.1          default_hb85057a_2
libdeflate                1.17                 h5eee18b_0
libedit                   3.1.20191231         he28a2e2_2    conda-forge
libevent                  2.1.12               hf998b51_1    conda-forge
libexpat                  2.5.0                hcb278e6_1    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libgcc-ng                 13.1.0               he5830b7_0    conda-forge
libgfortran-ng            13.1.0               h69a702a_0    conda-forge
libgfortran5              13.1.0               h15d22d2_0    conda-forge
libglib                   2.76.4               hebfc3b9_0    conda-forge
libgomp                   13.1.0               he5830b7_0    conda-forge
libiconv                  1.17                 h166bdaf_0    conda-forge
liblapack                 3.9.0           17_linux64_openblas    conda-forge
libllvm10                 10.0.1               he513fc3_3    conda-forge
libnsl                    2.0.0                h7f98852_0    conda-forge
libopenblas               0.3.23          pthreads_h80387f5_0    conda-forge
libpng                    1.6.39               h753d276_0    conda-forge
libpq                     12.15                hdbd6064_1
libsqlite                 3.42.0               h2797004_0    conda-forge
libstdcxx-ng              13.1.0               hfd8a6a1_0    conda-forge
libtiff                   4.5.0                h6adf6a1_2    conda-forge
libuuid                   2.38.1               h0b41bf4_0    conda-forge
libwebp                   1.2.4                h1daa5a0_1    conda-forge
libwebp-base              1.2.4                h5eee18b_1
libxcb                    1.15                 h0b41bf4_0    conda-forge
libxkbcommon              1.0.1                hfa300c1_0
libxml2                   2.9.14               h74e7548_0
libxslt                   1.1.35               h4e12654_0
libzlib                   1.2.13               hd590300_5    conda-forge
matplotlib                3.7.2           py311h38be061_0    conda-forge
matplotlib-base           3.7.2           py311h54ef318_0    conda-forge
munkres                   1.1.4              pyh9f0ad1d_0    conda-forge
ncurses                   6.4                  hcb278e6_0    conda-forge
nspr                      4.35                 h27087fc_0    conda-forge
nss                       3.89                 he45b914_0    conda-forge
numpy                     1.25.2          py311h64a7726_0    conda-forge
openssl                   3.1.2                hd590300_0    conda-forge
packaging                 23.1               pyhd8ed1ab_0    conda-forge
pcre2                     10.40                hc3806b6_0    conda-forge
pillow                    9.4.0           py311h6a678d5_0
pip                       23.2.1             pyhd8ed1ab_0    conda-forge
ply                       3.11                       py_1    conda-forge
pthread-stubs             0.4               h36c2ea0_1001    conda-forge
pyparsing                 3.0.9              pyhd8ed1ab_0    conda-forge
pyqt                      5.15.7          py311h6a678d5_0
pyqt5-sip                 12.11.0         py311h6a678d5_0
python                    3.11.4          hab00c5b_0_cpython    conda-forge
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python_abi                3.11                    3_cp311    conda-forge
qt-main                   5.15.2               h327a75a_7
qt-webengine              5.15.9               hd2b0992_4
qtwebkit                  5.212                h4eab89a_4
readline                  8.2                  h8228510_1    conda-forge
setuptools                68.0.0             pyhd8ed1ab_0    conda-forge
sip                       6.6.2           py311h6a678d5_0
six                       1.16.0             pyh6c4a22f_0    conda-forge
sqlite                    3.42.0               h2c6b66d_0    conda-forge
tk                        8.6.12               h27826a3_0    conda-forge
toml                      0.10.2             pyhd8ed1ab_0    conda-forge
tornado                   6.3.2           py311h459d7ec_0    conda-forge
tzdata                    2023c                h71feb2d_0    conda-forge
wheel                     0.41.1             pyhd8ed1ab_0    conda-forge
xorg-libxau               1.0.11               hd590300_0    conda-forge
xorg-libxdmcp             1.1.3                h7f98852_0    conda-forge
xz                        5.2.6                h166bdaf_0    conda-forge
zlib                      1.2.13               hd590300_5    conda-forge
zstd                      1.5.2                hfc55251_7    conda-forge


---From normal, no error
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                        main
_openmp_mutex             5.1                       1_gnu
blas                      1.0                         mkl
brotli                    1.0.9                h5eee18b_7
brotli-bin                1.0.9                h5eee18b_7
bzip2                     1.0.8                h7b6447c_0
ca-certificates           2023.05.30           h06a4308_0
contourpy                 1.0.5           py311hdb19cb5_0
cycler                    0.11.0             pyhd3eb1b0_0
dbus                      1.13.18              hb2f20db_0
expat                     2.4.9                h6a678d5_0
fontconfig                2.14.1               h52c9d5c_1
fonttools                 4.25.0             pyhd3eb1b0_0
freetype                  2.12.1               h4a9f257_0
giflib                    5.2.1                h5eee18b_3
glib                      2.69.1               he621ea3_2
gst-plugins-base          1.14.1               h6a678d5_1
gstreamer                 1.14.1               h5eee18b_1
icu                       58.2                 he6710b0_3
intel-openmp              2023.1.0         hdb19cb5_46305
jpeg                      9e                   h5eee18b_1
kiwisolver                1.4.4           py311h6a678d5_0
krb5                      1.20.1               h143b758_1
lcms2                     2.12                 h3be6417_0
ld_impl_linux-64          2.38                 h1181459_1
lerc                      3.0                  h295c915_0
libbrotlicommon           1.0.9                h5eee18b_7
libbrotlidec              1.0.9                h5eee18b_7
libbrotlienc              1.0.9                h5eee18b_7
libclang                  10.0.1          default_hb85057a_2
libdeflate                1.17                 h5eee18b_0
libedit                   3.1.20221030         h5eee18b_0
libevent                  2.1.12               hdbd6064_1
libffi                    3.4.4                h6a678d5_0
libgcc-ng                 11.2.0               h1234567_1
libgomp                   11.2.0               h1234567_1
libllvm10                 10.0.1               hbcb73fb_5
libpng                    1.6.39               h5eee18b_0
libpq                     12.15                hdbd6064_1
libstdcxx-ng              11.2.0               h1234567_1
libtiff                   4.5.0                h6a678d5_2
libuuid                   1.41.5               h5eee18b_0
libwebp                   1.2.4                h11a3e52_1
libwebp-base              1.2.4                h5eee18b_1
libxcb                    1.15                 h7f8727e_0
libxkbcommon              1.0.1                hfa300c1_0
libxml2                   2.9.14               h74e7548_0
libxslt                   1.1.35               h4e12654_0
lz4-c                     1.9.4                h6a678d5_0
matplotlib                3.7.1           py311h06a4308_1
matplotlib-base           3.7.1           py311ha02d727_1
mkl                       2023.1.0         h213fc3f_46343
mkl-service               2.4.0           py311h5eee18b_1
mkl_fft                   1.3.6           py311ha02d727_1
mkl_random                1.2.2           py311ha02d727_1
munkres                   1.1.4                      py_0
ncurses                   6.4                  h6a678d5_0
nspr                      4.35                 h6a678d5_0
nss                       3.89.1               h6a678d5_0
numpy                     1.25.2          py311h08b1b3b_0
numpy-base                1.25.2          py311hf175353_0
openssl                   3.0.10               h7f8727e_0
packaging                 23.0            py311h06a4308_0
pcre                      8.45                 h295c915_0
pillow                    9.4.0           py311h6a678d5_0
pip                       23.2.1          py311h06a4308_0
ply                       3.11            py311h06a4308_0
pyparsing                 3.0.9           py311h06a4308_0
pyqt                      5.15.7          py311h6a678d5_0
pyqt5-sip                 12.11.0         py311h6a678d5_0
python                    3.11.4               h955ad1f_0
python-dateutil           2.8.2              pyhd3eb1b0_0
qt-main                   5.15.2               h327a75a_7
qt-webengine              5.15.9               hd2b0992_4
qtwebkit                  5.212                h4eab89a_4
readline                  8.2                  h5eee18b_0
setuptools                68.0.0          py311h06a4308_0
sip                       6.6.2           py311h6a678d5_0
six                       1.16.0             pyhd3eb1b0_1
sqlite                    3.41.2               h5eee18b_0
tbb                       2021.8.0             hdb19cb5_0
tk                        8.6.12               h1ccaba5_0
toml                      0.10.2             pyhd3eb1b0_0
tornado                   6.3.2           py311h5eee18b_0
tzdata                    2023c                h04d1e81_0
wheel                     0.38.4          py311h06a4308_0
xz                        5.4.2                h5eee18b_0
zlib                      1.2.13               h5eee18b_0
zstd                      1.5.5                hc292b87_0

Environment info

active environment : jplerror3
    active env location : /home/dennis/.conda/envs/jplerror3
            shell level : 2
       user config file : /home/dennis/.condarc
 populated config files :
          conda version : 23.5.2
    conda-build version : not installed
         python version : 3.11.4.final.0
       virtual packages : __archspec=1=x86_64
                          __glibc=2.31=0
                          __linux=5.4.0=0
                          __unix=0=0
       base environment : /opt/conda  (read only)
      conda av data dir : /opt/conda/etc/conda
  conda av metadata url : None
           channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /opt/conda/pkgs
                          /home/dennis/.conda/pkgs
       envs directories : /home/dennis/.conda/envs
                          /opt/conda/envs
               platform : linux-64
             user-agent : conda/23.5.2 requests/2.29.0 CPython/3.11.4 Linux/5.4.0-153-generic ubuntu/20.04.5 glibc/2.31
                UID:GID : 1000:1000
             netrc file : None
           offline mode : False
@dennischen dennischen added the bug label Aug 14, 2023
@dopplershift
Copy link
Member

That actually looks like a problem with PIL in your environment. What happens if you run python -c 'from PIL import Image'?

@dennischen
Copy link
Author

Same error in jplerror3

(jplerror3) dennis@slurm:~$ python -c "from PIL import Image"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/dennis/.conda/envs/jplerror3/lib/python3.11/site-packages/PIL/Image.py", line 103, in <module>
    from . import _imaging as core
ImportError: libtiff.so.5: cannot open shared object file: No such file or directory

But, I made a new clean env and install pillow only, it don't throw the error by import pil.

conda create -n pilerr2
conda activate pilerr2
#force version 9.4.0 as same as instal matplotlib
conda install -c conda-forge python pillow=9.4.0 -y 
python -c "from PIL import Image"
#no error here

the conda list information

_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       2_gnu    conda-forge
bzip2                     1.0.8                h7f98852_4    conda-forge
ca-certificates           2023.7.22            hbcca054_0    conda-forge
freetype                  2.12.1               hca18f0e_1    conda-forge
lcms2                     2.15                 haa2dc70_1    conda-forge
ld_impl_linux-64          2.40                 h41732ed_0    conda-forge
lerc                      4.0.0                h27087fc_0    conda-forge
libdeflate                1.18                 h0b41bf4_0    conda-forge
libexpat                  2.5.0                hcb278e6_1    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libgcc-ng                 13.1.0               he5830b7_0    conda-forge
libgomp                   13.1.0               he5830b7_0    conda-forge
libjpeg-turbo             2.1.5.1              h0b41bf4_0    conda-forge
libnsl                    2.0.0                h7f98852_0    conda-forge
libpng                    1.6.39               h753d276_0    conda-forge
libsqlite                 3.42.0               h2797004_0    conda-forge
libstdcxx-ng              13.1.0               hfd8a6a1_0    conda-forge
libtiff                   4.5.1                h8b53f26_0    conda-forge
libuuid                   2.38.1               h0b41bf4_0    conda-forge
libwebp-base              1.3.1                hd590300_0    conda-forge
libxcb                    1.13              h7f98852_1004    conda-forge
libzlib                   1.2.13               hd590300_5    conda-forge
ncurses                   6.4                  hcb278e6_0    conda-forge
openjpeg                  2.5.0                hfec8fc6_2    conda-forge
openssl                   3.1.2                hd590300_0    conda-forge
pillow                    9.4.0           py311h573f0d3_2    conda-forge
pip                       23.2.1             pyhd8ed1ab_0    conda-forge
pthread-stubs             0.4               h36c2ea0_1001    conda-forge
python                    3.11.4          hab00c5b_0_cpython    conda-forge
python_abi                3.11                    3_cp311    conda-forge
readline                  8.2                  h8228510_1    conda-forge
setuptools                68.0.0             pyhd8ed1ab_0    conda-forge
tk                        8.6.12               h27826a3_0    conda-forge
tzdata                    2023c                h71feb2d_0    conda-forge
wheel                     0.41.1             pyhd8ed1ab_0    conda-forge
xorg-libxau               1.0.11               hd590300_0    conda-forge
xorg-libxdmcp             1.1.3                h7f98852_0    conda-forge
xz                        5.2.6                h166bdaf_0    conda-forge
zstd                      1.5.2                hfc55251_7    conda-forge

===
the package channel is different

# in jplerror3, pillow is not be installed directly and get libtiff.so.5 not found error
pillow                    9.4.0           py311h6a678d5_0

# in pilerr2, pillow is installed directly, no error
pillow                    9.4.0           py311h573f0d3_2    conda-forge

@dennischen
Copy link
Author

A more clear test case can reproduce this.

conda create -n case1 -y
conda activate case1
conda install -c conda-forge python matplotlib -y
python -c "import matplotlib.pyplot as plt"

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/dennis/.conda/envs/case1/lib/python3.11/site-packages/matplotlib/__init__.py", line 129, in <module>
    from . import _api, _version, cbook, _docstring, rcsetup
  File "/home/dennis/.conda/envs/case1/lib/python3.11/site-packages/matplotlib/rcsetup.py", line 27, in <module>
    from matplotlib.colors import Colormap, is_color_like
  File "/home/dennis/.conda/envs/case1/lib/python3.11/site-packages/matplotlib/colors.py", line 51, in <module>
    from PIL import Image
  File "/home/dennis/.conda/envs/case1/lib/python3.11/site-packages/PIL/Image.py", line 103, in <module>
    from . import _imaging as core
ImportError: libtiff.so.5: cannot open shared object file: No such file or directory
conda create -n case2 -y
conda activate case2
conda install -c conda-forge python matplotlib pillow=9.4.0 -y
python -c "import matplotlib.pyplot as plt"


It looks like install matplotlib from conda-forge cann't get same pillow from conda-forget since this week. (no error in last week)

I am new to python and conda, no sure the root cause

@dopplershift
Copy link
Member

The conda-forge environment that errors is mixing packages from different channels, which is not a supported configuration. Does it work if you create the environment using only conda-forge:

conda create -c conda-forge -n case3 python matplotlib

@dennischen
Copy link
Author

just tried your suggestion

conda create -c conda-forge -n case3 python matplotlib

but the pillow is still not from conda-forge

pillow                    9.4.0           py311h6a678d5_0

and run import matpoltlib get same error.

I doubt it is a cach issue, but get same error in new VM.
any other idea? cloud you run this test correctly in your env?

@dopplershift
Copy link
Member

I can't reproduce this on my macOS system, so it's something specific to linux it seems. Some potential things to try:

  • Turn on strict channel priority: conda config --set channel_priority strict
  • Replace the defaults channel in your .condarc with only conda-forge to completely eliminate the possibility of mixing them
  • matplotlib itself is just matplotlib-base + pyqt, so unless you need a pyqt-based GUI, try using matplotlib-base instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants