2

I have a script that is written in Python. The author decided to use new features only available in Python 3, so I had to update my version.

Now I am having trouble because the script crashes on an import statement, so I decided to do some debugging. I came to the conclusion that my Python 3 cannot import Image from PIL.

In Python 2:

Python 2.7.10 (default, Aug 22 2015, 20:33:39) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image

Does not give an error, but in Python 3:

Python 3.5.0 (v3.5.0:374f501f4567, Sep 12 2015, 11:00:19) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'PIL'

Why is this happening and how can I fix this?

4

1 回答 1

5

PIL 不是标准库;您为 Python 2 安装了它,但 Python 3 不(也不能)使用该安装。

在 Python 3 中也显式安装 PIL(或者更确切地说是 Pillow fork):

python3 -m ensurepip  # optional, makes sure pip is installed
python3 -m pip install Pillow
于 2015-11-03T19:25:35.380 回答