ImportError: cannot import name _imaging
Solution 1
I ran into this problem as well. It can happen if you have PIL installed, then install Pillow on top of it.
Go to /usr/local/lib/python2.7/dist-packages/ and delete anything with "PIL" in the name (including directories). If the Pillow .egg file is there you might as well delete that too. Then re-install Pillow.
substitute "python2.7" for the version of python you're using.
Solution 2
I had the same problem and I solved that by upgrading this package using the command below:
pip install -U Pillow
Solution 3
This also happens if you built Pillow
in one OS and then copied the contents of site-packages
to another one. For example, if you are creating AWS Lambda deployment package, that's the error you will face when running the Lambda function. If that's the case, then Pillow needs to be installed in a Amazon Linux instance and you have to use the resulting site-packages
in your deployment package. See instructions and details here:
http://docs.aws.amazon.com/lambda/latest/dg/with-s3-example-deployment-pkg.html
Solution 4
What is your version of pillow?
Pillow >= 2.1.0 no longer supports import _imaging
. Please use from PIL.Image import core as _imaging
instead. Here's the official documentation.
Solution 5
I have got the same error with Python 3.6. Upgrading Pillow did the job for me.
sudo python3.6 -m pip install Pillow --upgrade
Probably for other python versions use your version instead of 3.6.
tomooka
Updated on July 08, 2022Comments
-
tomooka almost 2 years
I installed
Pillow
, and after I want to do:from PIL import Image
I get the following error:
Traceback (most recent call last): File "<console>", line 1, in <module> File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 61, in <module> ImportError: cannot import name _imaging
However, if I import these separately, everything is fine, ie:
import _imaging import Image
Do you know what the problem might be?
-
tomooka almost 10 yearsAnd btw, PIL do have a folder, under /usr/local/lib/python2.7/dist-packages/PIL
-
James Paul Shaulis almost 10 yearsimport PIL not import PiL.
-
tomooka almost 10 yearsDude, as I said, PiL was a typo. Originally i did import PIL :D, and still it doesnt work
-
James Paul Shaulis almost 10 yearsTry python3 import PIL
-
Nick about 8 yearsOn my Mac I had to do this under
/usr/local/lib/python2.7/site-packages
Fixed, thanks. -
JonathanGailliez over 6 yearsI use CodeBuild in combination with Elastic Container Repository. ECR is used to store the Docker image used by CodeBuild. I was using an image based on the python:3.5.2 image and I had the error message. Once I switched to amazonlinux:latest and installed Python manually in it, the issue was fixed. Thanks a lot for your insight!
-
joarleymoraes over 6 yearsGlad it helped :)
-
blogbydev over 6 yearsDoes this mean that i can't create the zip file with proper contents in it on my Mac?
-
jupiar over 5 yearsOn Ubuntu, I ran
sudo pip3 uninstall uninstall pip3
4 times (because there was always still something to remove) until there was nothing left to remove. And then runningpip3 install -U pillow --user
, no more errors from Pillow. -
Lost Crotchet about 5 yearsThis solution won't work for me because I am trying to create a portable app using embedded python zip. Pip appears to no longer work in embedded python either so I can't install via the embedded interpreter either.
-
zzfima about 4 yearsthanks! pip uninstall pillow pip install pillow was enough
-
loved.by.Jesus over 3 yearsThanks you led me to the solution. In Ubuntu 16.04. I had problems running in Python3. It was enough for me to remove the "official" package
python3-pil
(i.e.,sudo apt-get remove python3-pil
), because I had installed Pillow viapip
-
CristiC777 over 3 yearsI editet in PIL\Image.py with from PIL.Image import core as _imaging and Exception Value: cannot import name 'core'
-
Naresh Kumar about 3 yearsUnistall and reinstall of pillow worked perfectly. pip uninstall pillow pip install -U pillow
-
sugab almost 3 yearsTry this first before you implement the "answer" above. This solution works for me.
-
mustafa over 2 yearsyou should also ensure that pip3 is referring to the correct Python version. If your Lambda function is Python3.8, you better use
pip3.8