在 Windows 上安装 Pillow for Python
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20596204/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Installing Pillow for Python on Windows
提问by mkosmala
I am fairly new to Python and trying to install the Pillow package on Windows 7. I downloaded and ran the MS Windows installer Pillow-2.2.1.win-amd64-py3.3.exe from here. It appeared to install fine. If I run the simple line of code:
我对 Python 相当陌生,并试图在 Windows 7 上安装 Pillow 包。我从这里下载并运行了 MS Windows 安装程序 Pillow-2.2.1.win-amd64-py3.3.exe 。它似乎安装得很好。如果我运行简单的代码行:
from PIL import Image
directly from the Python interpreter, it runs fine. A help() on PIL gives me the package contents.
直接来自 Python 解释器,它运行良好。PIL 上的 help() 为我提供了包内容。
But when I try to run the same line of code from within a script, I get an ImportError: No module named PIL. What am I missing?
但是当我尝试从脚本中运行同一行代码时,我得到了一个ImportError: No module named PIL. 我错过了什么?
(Note that I've been able to import sysand import MySQLdbfrom within scripts just fine.)
(请注意,我已经能够import sys和import MySQLdb从脚本中就好了。)
Resolved: sure, enough, I'm running Python 2.7 when I run scripts. (I think I vaguely recall having to install an older version so I could interface with MySQL.) Thank you all for pointing out that I should check the version being used.
已解决:当然,当我运行脚本时,我正在运行 Python 2.7。(我想我依稀记得必须安装一个旧版本,这样我才能与 MySQL 交互。)谢谢大家指出我应该检查正在使用的版本。
采纳答案by MattDMo
For third-party modules for Windows, my go-to resource is Christoph Gohlke's Python Extension Packages for Windows. You can find the latest version of Pillow here. Make sure you're working with the python.org version of Python.
对于适用于 Windows 的第三方模块,我的首选资源是 Christoph Gohlke 的适用于 Windows的Python 扩展包。您可以在此处找到 Pillow 的最新版本。确保您使用的是 python.org 版本的 Python。
As far as your specific error, it's hard to tell exactly without a traceback, but make sure your script is calling the correct version of Python. If you have also installed Python 2.7, for example, your script may be calling that instead of 3.3.
就您的具体错误而言,如果没有回溯很难准确判断,但请确保您的脚本正在调用正确版本的 Python。例如,如果您还安装了 Python 2.7,您的脚本可能会调用它而不是 3.3。
回答by alexandrul
In such cases I'm simply printing the sys.pathat the beginning of the script in trouble and comparing it with the one from the working python interpreter. In most cases I was running the script with a different python interpreter.
在这种情况下,我只是sys.path在遇到麻烦的脚本的开头打印,并将其与工作 python 解释器中的进行比较。在大多数情况下,我使用不同的 python 解释器运行脚本。
回答by Saurabh
In my case , I was referring to wrong pip folder. Changed virtual environment in pycharm to point to right pip folder to solve this issue
就我而言,我指的是错误的 pip 文件夹。将pycharm中的虚拟环境更改为指向正确的pip文件夹以解决此问题
import sys
print ( sys.path )

