Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python2与Python3导入_Python_Python 2.7_Python Import_Pillow_Python 3.5 - Fatal编程技术网

Python2与Python3导入

Python2与Python3导入,python,python-2.7,python-import,pillow,python-3.5,Python,Python 2.7,Python Import,Pillow,Python 3.5,我有一个用Python编写的脚本。作者决定使用仅在Python3中可用的新功能,因此我必须更新我的版本 现在我遇到了麻烦,因为脚本在import语句上崩溃,所以我决定进行一些调试。我得出的结论是,我的Python3无法从PIL导入Image 在Python 2中: 不会给出错误,但在Python 3中: Python 3.5.0(v3.5.0:374F501F45672015年9月12日11:00:19) [GCC 4.2.1(苹果公司建造5666)(dot 3)]关于达尔文 有关详细信息,请键

我有一个用Python编写的脚本。作者决定使用仅在Python3中可用的新功能,因此我必须更新我的版本

现在我遇到了麻烦,因为脚本在import语句上崩溃,所以我决定进行一些调试。我得出的结论是,我的Python3无法从
PIL
导入
Image

在Python 2中:

不会给出错误,但在Python 3中:

Python 3.5.0(v3.5.0:374F501F45672015年9月12日11:00:19)
[GCC 4.2.1(苹果公司建造5666)(dot 3)]关于达尔文
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
>>>从PIL导入图像
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
ImportError:没有名为“PIL”的模块

为什么会发生这种情况?我如何修复它?PIL不是一个标准库;您为Python2安装了它,但Python3没有(也不能)使用该安装

在Python 3中也显式安装PIL(或者更确切地说,枕头叉):

python3 -m ensurepip  # optional, makes sure pip is installed
python3 -m pip install Pillow

PIL不是标准库,您需要安装它。我推荐Pillow fork(更新的PIL打包和bug修复)。Python2和Python3的模块是分开安装的。Python3不能“共享”您已经在Python2下安装的模块。如果您开始使用Python3,您需要安装想要使用的任何库的Python3版本。您在Python3安装中安装了pillow吗?
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'
python3 -m ensurepip  # optional, makes sure pip is installed
python3 -m pip install Pillow