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:14

you have to install Image and pillow with your python package.

type

python -m pip install image 

or run command prompt (in windows), then navigate to the scripts folder

cd C:\Python27\Scripts

then run below command

pip install image
查看更多
劫难
3楼-- · 2019-01-07 04:15

Sometimes I get this type of error running a Unitest in python. The solution is to uninstall and install the same package on your virtual environment.

Using this commands:

pip uninstall PIL

and

pip install  PIL 

If for any reason you get an error, add sudo at the beginning of the command and after hitting enter type your password.

查看更多
戒情不戒烟
4楼-- · 2019-01-07 04:16

At first install Pillow with

pip install Pillow

or as follows

c:\Python35>python -m pip install Pillow

Then in python code you may call

from PIL import Image

"Pillow is a fork of PIL, the Python Imaging Library, which is no longer maintained. However, to maintain backwards compatibility, the old module name is used." From pillow installed, but "no module named pillow" - python2.7 - Windows 7 - python -m install pillow

查看更多
Melony?
5楼-- · 2019-01-07 04:16

On windows, try checking the path to the location of the PIL library. On my system, I noticed the path was

\Python26\Lib\site-packages\pil instead of \Python26\Lib\site-packages\PIL  

after renaming the pil folder to PIL, I was able to load the PIL module.

查看更多
混吃等死
6楼-- · 2019-01-07 04:18

On Windows, you need to download it and install the .exe

https://pypi.python.org/pypi/Pillow/2.7.0

查看更多
甜甜的少女心
7楼-- · 2019-01-07 04:20

This worked for me on Ubuntu 16.04:

sudo apt-get install python-imaging

I found this on Wikibooks after searching for about half an hour.

查看更多
登录 后发表回答