Python 2.7 - ImportError: No module named Image

2019-07-05 04:43发布

问题:

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 Image library. 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".

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

回答1:

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:

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



回答2:

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:

from PIL import Image

but make sure Pillow is installed. Works for me.



回答3:

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

  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