DLL load failed while importing _imaging on clean anaconda install

570 Views Asked by At

I installed anaconda for the first time and have had to uninstall and reinstall many times due to different issues I've faced. This is my first time working with the program so I don't know much about it.

On a clean install I entered the following into the anaconda prompt:

conda update --all
conda install pyreadstat --channel conda-forge --yes
conda install geopandas --channel conda-forge

Then, when launching Jupyter and running the following:

import pandas as pd
import seaborn as sns

I receive the following error:

if __version__ != getattr(core, "PILLOW_VERSION", None):
            msg = (
              "The _imaging extension was built for another version of Pillow or PIL:\n"
              f"Core version: {getattr(core, 'PILLOW_VERSION', None)}\n"
              f"Pillow version: {__version__}"
ImportError: DLL load failed while importing _imaging: The specified module could not be found.

When running this code:

import pandas as pd
poll_url = 'http://projects.fivethirtyeight.com/general-model/president_general_polls_2016.csv'
polls = pd.read_csv(poll_url)
polls

polls.sort_values('startdate', ascending=False, inplace=True)
polls.head()

polls.drop(columns=['cycle','branch','matchup','forecastdate'], inplace=True)
polls.head(2)

polls.plot.line(xlim=('2016-06','2016-11'))

I receive the error:

ImportError: matplotlib is required for plotting when the default backend "matplotlib" is selected.

I had trouble installing geopandas for several days and would get stuck in solving environment for hours at a time and a few times my navigator wouldn't open after.

Installation instructions are from the Murach book Data Analysis for Python, and the code shown above is as well. I'm assuming there's some kind of compatibility error somewhere? Solutions I've seen are to use pip, which can corrupt your environment when mixed with conda commands, or creating a separate environment, but the book requires you to work in the base. Some of the packages and versions I have are:

conda 23.7.3
geopandas 0.13.2
ipython 8.12.2
matplotlib 3.7.1
pandas 2.0.3
pillow 9.4.0
python 3.11.4

Thanks!

1

There are 1 best solutions below

16
Musabbir Arrafi On

I faced this same error somedays ago after installing geopandas some day ago. My python version is 3.10.12. I solved this by doing the following steps:

Downgraded my pillow package to version-9.0.0. It is working fine since then. Just do this:

conda remove pillow

then install pillow-9.0.0 with pip:

pip install pillow==9.0.0

I don't know the exact reason for the conflict between matplotlib and pillow but downgrading it worked for me. Also I found the solutio from here: https://github.com/msys2/MINGW-packages/issues/11103

Edit: How to create a new conda environment with specific python version

Choose the python version you want. Then activate the environment.

conda create -n myenv python=3.10
conda activate myenv