Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannot import name _imaging

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?

like image 981
tomooka Avatar asked Aug 16 '14 13:08

tomooka


3 Answers

I had the same problem and I solved that by upgrading this package using the command below:

pip install -U Pillow
like image 93
Benyamin Jafari Avatar answered Nov 08 '22 08:11

Benyamin Jafari


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

like image 42
joarleymoraes Avatar answered Nov 08 '22 08:11

joarleymoraes


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.

like image 40
cbeytas Avatar answered Nov 08 '22 09:11

cbeytas