Python 2.7 - 导入错误:没有名为 Image 的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18776988/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 11:48:43  来源:igfitidea点击:

Python 2.7 - ImportError: No module named Image

pythonwindowsopencvinstallation

提问by bao tran dang

Recently, I have been studying OpenCV to detect and recognize faces using C++. In order to execute source code demonstration from the OpenCV website I need to run Python to crop image first. Unfortunately, the message error is 'ImportError: No module named Image'when I run the Python script (this script is provided by OpenCV website). I installed "python-2.7.amd64" and downloaded "PIL-1.1.7.win32-py2.7" to install Imagelibrary. However, the message error is 'Python version 2.7 required, which was not found in the registry'. And then, I downloaded the script written by Joakim L?w for Secret Labs AB / PythonWare to register registry in my computer. But the message error is "Unable to register. You probably have the another Python installation".

最近,我一直在研究 OpenCV 使用 C++ 检测和识别人脸。为了从 OpenCV 网站执行源代码演示,我需要先运行 Python 来裁剪图像。不幸的是,消息错误是'ImportError: No module named Image'在我运行 Python 脚本时(此脚本由 OpenCV 网站提供)。我安装了“python-2.7.amd64”并下载了“PIL-1.1.7.win32-py2.7”来安装Image库。但是,消息错误是'Python version 2.7 required, which was not found in the registry'。然后,我下载了 Joakim L?w 为 Secret Labs AB / PythonWare 编写的脚本,以便在我的计算机中注册注册表。但消息错误是"Unable to register. You probably have the another Python installation".

I spent one month to search this issue on the internet but I cannot find the answer. Please support me to resolve my issue.

我花了一个月的时间在互联网上搜索这个问题,但我找不到答案。请支持我解决我的问题。

Thanks, Tran Dang Bao

谢谢,Tran Dang Bao

回答by ovrwngtvity

Try to put the python(2.7) at your Windows path. Do the following steps:

尝试将 python(2.7) 放在您的 Windows 路径中。执行以下步骤:

  1. Open System Properties (Win+Pause) or My Computer and right-click then Properties
  2. Switch to the Advanced tab
  3. Click Environment Variables
  4. Select PATH in the System variables section
  5. Click Edit
  6. Add python's path to the end of the list (the paths are separated by semicolons). example C:\Windows;C:\Windows\System32;C:\Python27
  1. 打开系统属性(Win+Pause)或我的电脑,然后右键单击属性
  2. 切换到高级选项卡
  3. 单击环境变量
  4. 在系统变量部分选择 PATH
  5. 单击编辑
  6. 将python的路径添加到列表的末尾(路径用分号分隔)。例子C:\Windows;C:\Windows\System32;C:\Python27

回答by Mark Tolonen

You installed the 64-bit version of Python, but the 32-bit version of PIL. Either switch to the 32-bit version of Python, or you need a 64-bit version of PIL (not available that I could find). There is pillow, a PIL-compatible replacement that might work. A 64-bit version is available here:

您安装了 64 位版本的 Python,但安装了 32 位版本的 PIL。要么切换到32 位版本的 Python,要么您需要一个 64 位版本的 PIL(我找不到)。有pillow一个与 PIL 兼容的替代品可能会起作用。64 位版本可在此处获得:

Pillow-2.1.0.win-amd64-py2.7.?exe

Pillow-2.1.0.win-amd64-py2.7.?exe

回答by Vishal R

The solution is very simple. You don't need to worry about x86 or 64 bit, all you have to do is import as follows:

解决方法很简单。您无需担心 x86 或 64 位,您所要做的就是按如下方式导入:

from PIL import Image

but make sure Pillow is installed. Works for me.

但请确保已安装 Pillow。为我工作。