Search code examples
pythonmatplotlibanacondapython-imaging-library

Matplotlib cannot find the installed PIL module


I want to print rcParams to see the settings during stages of my program.

Here are my imports:

import matplotlib as mpl
from matplotlib import rcParams

I've tried the following:

print(mpl.rcParamsDefault),print(mpl.rcParams) and print(rcParams)

I get the same error message for all three:

Traceback (most recent call last):
  File "e:\Minitab_Killer\rcParams_print_out.py", line 1, in <module>
    import matplotlib as mpl
  File "C:\Users\D\miniconda3\lib\site-packages\matplotlib\__init__.py", line 107, in <module>
    from . import _api, cbook, docstring, rcsetup
  File "C:\Users\D\miniconda3\lib\site-packages\matplotlib\rcsetup.py", line 24, in <module>
    from matplotlib import _api, animation, cbook
  File "C:\Users\D\miniconda3\lib\site-packages\matplotlib\animation.py", line 34, in <module>
    from PIL import Image
  File "C:\Users\D\miniconda3\lib\site-packages\PIL\Image.py", line 103, in <module>
    from . import _imaging as core
ImportError: DLL load failed while importing _imaging: The specified module could not be found.

I found this answer, some resolve this by fixing their pillow installation. I am using anaconda so I ran the conda install -c anaconda pillow command and it updated pillow but the error message did not change.

I tried this answer and ran pip install --force pillow, same error message.

While I tried the pip answer I desire a pure conda solution.

From conda list here are the relevant packages: python 3.10.9,pillow 9.4.0,matplotlib 3.5.3.

Update:

Tried this :pip install --force pillow, and this: Pillow 9.0.0 getting the following error:

Traceback (most recent call last):
  File "e:\Minitab_Killer\rcParams_print_out.py", line 2, in <module>
    from matplotlib import rcParams 
  File "C:\Users\D\miniconda3\lib\site-packages\matplotlib\__init__.py", line 107, in <module>
    from . import _api, cbook, docstring, rcsetup
  File "C:\Users\D\miniconda3\lib\site-packages\matplotlib\rcsetup.py", line 24, in <module>
    from matplotlib import _api, animation, cbook
  File "C:\Users\D\miniconda3\lib\site-packages\matplotlib\animation.py", line 34, in <module>
    from PIL import Image
  File "C:\Users\D\miniconda3\lib\site-packages\PIL\Image.py", line 103, in <module>
    from . import _imaging as core
ImportError: DLL load failed while importing _imaging: The specified module could not be found.

What should I try next?


Solution

  • I posted a bug report on GitHub here.

    Turns out this was not a bug. Andrew Murray offered multiple things to try for resolution, in my case conda upgrade conda solved my problem.