可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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?
回答1:
On some installs of PIL, You must do
import Image
instead of import PIL
(PIL is in fact not always imported this way). Since import Image
works for you, this means that you have in fact installed PIL.
Having a different name for the library and the Python module is unusual, but this is what was chosen for (some versions of) PIL.
You can get more information about how to use this module from the official tutorial.
PS: In fact, on some installs, import PIL
does work, which adds to the confusion. This is confirmed by an example from the documentation, as @JanneKarila found out, and also by some more recent versions of the MacPorts PIL package (1.1.7).
回答2:
In shell, run:
pip install Pillow
Attention: PIL is deprecated, and pillow is the successor.
回答3:
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..
回答4:
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
回答5:
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.
回答6:
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.
回答7:
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.
回答8:
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
回答9:
instead of PIL use Pillow it works
easy_install Pillow
or
pip install Pillow
回答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
回答11:
if you use anaconda:
conda install pillow
回答12:
On Windows, you need to download it and install the .exe
https://pypi.python.org/pypi/Pillow/2.7.0
回答13:
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.
回答14:
I recently installed Leap. I Tried openshot and it didn't start. So came here and found a suggestion to start from the Terminal to see if there were any error.
The error I had was error missing mlt
. So I installed the python-mlt
module from Yast and imported it, tried to start but next openshot said missing pil.
I Followed the Pillow suggestion to install because Yast couldn't find any pil and imported pil. That went ok but did not start and showed Error missing goocanvas
.
The I installed goocanvas
with Yast, imported it in python, and Openshot fired up !!
With a lot of errors in the terminal like missing Vimeoclient
and lots of attributeerrors
. Well, will see if it is of any influence working with it.
回答15:
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.
回答16:
I had the same problem and i fixed it by checking what version pip (pip3 --version
) is, then realizing I'm typing python<uncorrect version> filename.py
instead of python<correct version> filename.py
回答17:
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