Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't Python import Image from PIL?

The single line that I am trying to run is the following:

from PIL import Image 

However simple this may seem, it gives an error:

Traceback (most recent call last):   File "C:\...\2014-10-22_12-49.py", line 1, in <module>     from PIL import Image   File "C:\pyzo2014a\lib\site-packages\PIL\Image.py", line 29, in <module>     from PIL import VERSION, PILLOW_VERSION, _plugins ImportError: cannot import name 'VERSION' 

In case that's helpful, I installed pillow from https://pypi.python.org/pypi/Pillow/2.6.1 (file Pillow-2.6.1.win-amd64-py3.4.exe) before running this (before that there was already som PIL install, which I uninstalled). The script is run in Pyzo with Python version 3.4.1.

What is going wrong, how can I import Image?

like image 373
Betohaku Avatar asked Oct 22 '14 11:10

Betohaku


People also ask

Why PIL is not working in Python?

The Python error "ModuleNotFoundError: No module named 'PIL'" occurs for multiple reasons: Not having the Pillow package installed by running pip install Pillow . Installing the package in a different Python version than the one you're using. Installing the package globally and not in your virtual environment.

How do I import an image into Python using PIL?

To load the image, we simply import the image module from the pillow and call the Image. open(), passing the image filename. Instead of calling the Pillow module, we will call the PIL module as to make it backward compatible with an older module called Python Imaging Library (PIL).

How do I open a PIL image?

Image. open() Opens and identifies the given image file. This is a lazy operation; this function identifies the file, but the file remains open and the actual image data is not read from the file until you try to process the data (or call the load() method).


1 Answers

I had the same error. Here was my workflow. I first installed PIL (not Pillow) using

pip install --no-index -f https://dist.plone.org/thirdparty/ -U PIL 

Then I found Pillow and installed it using

pip install Pillow 

What fixed my issues was uninstalling both and reinstalling Pillow

pip uninstall PIL pip uninstall Pillow pip install Pillow 
like image 91
Trent Avatar answered Nov 07 '22 14:11

Trent