ImportError: cannot import name _imaging

99,191

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?

enter image description here

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.

Share:
99,191
tomooka
Author by

tomooka

Updated on July 08, 2022

Comments

  • tomooka
    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
    tomooka almost 10 years
    And btw, PIL do have a folder, under /usr/local/lib/python2.7/dist-packages/PIL
  • James Paul Shaulis
    James Paul Shaulis almost 10 years
    import PIL not import PiL.
  • tomooka
    tomooka almost 10 years
    Dude, as I said, PiL was a typo. Originally i did import PIL :D, and still it doesnt work
  • James Paul Shaulis
    James Paul Shaulis almost 10 years
    Try python3 import PIL
  • Nick
    Nick about 8 years
    On my Mac I had to do this under /usr/local/lib/python2.7/site-packages Fixed, thanks.
  • JonathanGailliez
    JonathanGailliez over 6 years
    I 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
    joarleymoraes over 6 years
    Glad it helped :)
  • blogbydev
    blogbydev over 6 years
    Does this mean that i can't create the zip file with proper contents in it on my Mac?
  • jupiar
    jupiar over 5 years
    On 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 running pip3 install -U pillow --user, no more errors from Pillow.
  • Lost Crotchet
    Lost Crotchet about 5 years
    This 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
    zzfima about 4 years
    thanks! pip uninstall pillow pip install pillow was enough
  • loved.by.Jesus
    loved.by.Jesus over 3 years
    Thanks 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 via pip
  • CristiC777
    CristiC777 over 3 years
    I editet in PIL\Image.py with from PIL.Image import core as _imaging and Exception Value: cannot import name 'core'
  • Naresh Kumar
    Naresh Kumar about 3 years
    Unistall and reinstall of pillow worked perfectly. pip uninstall pillow pip install -U pillow
  • sugab
    sugab almost 3 years
    Try this first before you implement the "answer" above. This solution works for me.
  • mustafa
    mustafa over 2 years
    you should also ensure that pip3 is referring to the correct Python version. If your Lambda function is Python3.8, you better use pip3.8