ImportError: cannot import name _imaging

2019-01-24 10:17发布

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?

4条回答
何必那么认真
2楼-- · 2019-01-24 10:39

For pillow to work PIL must be in /usr/local/lib/python2.7 or3/dist-packages/PIL.py.

In dist-packages PIL.py should have a folder.

1) sudo apt-get update 2) pip install Pillow

PIL != PiL, have a nice day.

查看更多
狗以群分
3楼-- · 2019-01-24 10:52

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

查看更多
我只想做你的唯一
4楼-- · 2019-01-24 10:59

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.

查看更多
再贱就再见
5楼-- · 2019-01-24 11:04

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. Link tot he official document

查看更多
登录 后发表回答