ImportError: No module named PIL

2019-01-07 03:59发布

I use this command in the shell to install PIL:

easy_install PIL

then I run python and type this: import PIL. But I get this error:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
ImportError: No module named PIL

I've never had such problem, what do you think?

17条回答
甜甜的少女心
2楼-- · 2019-01-07 04:03

On a different note, I can highly recommend the use of Pillow which is backwards compatible with PIL and is better maintained/will work on newer systems.

When that is installed you can do

import PIL 

or

from PIL import Image

etc..

查看更多
SAY GOODBYE
3楼-- · 2019-01-07 04:03

I had the same issue while importing PIL and further importing the ImageTk and Image modules. I also tried installing PIL directly through pip. but not success could be achieved. As in between it has been suggested that PIL has been deprectaed, thus, tried to install pillow through pip only. pillow was successfully installed, further, the PIL package was made under the path : python27/Lib/site-packages/.

Now both Image and ImageTk could be imported.

查看更多
做个烂人
4楼-- · 2019-01-07 04:08

I used conda-forge to install pillow version 5, and that seemed to work for me:

conda install --channel conda-forge pillow=5

the normal conda install pillow did NOT work for me.

查看更多
太酷不给撩
5楼-- · 2019-01-07 04:10

You will need to install Image and pillow with your python package. Rest assured, the command line will take care of everything for you.

Hit

python -m pip install image

查看更多
疯言疯语
6楼-- · 2019-01-07 04:10

You are probably missing the python headers to build pil. If you're using ubuntu or the likes it'll be something like

apt-get install python-dev
查看更多
Luminary・发光体
7楼-- · 2019-01-07 04:13

In shell, run:

pip install Pillow

Attention: PIL is deprecated, and pillow is the successor.

查看更多
登录 后发表回答