[python] 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?

The answer is


In Ubuntu OS, I solved it with the followings commands

pip install Pillow
apt-get install python-imaging

And sorry, dont ask me why, it's up to me ;-)


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

I had the same issue, and did this to fix it:

  1. In command prompt

    pip install Pillow ##
    
  2. Ensure that you use

    from PIL import Image
    

I in Image has to be capital. That was the issue in my case.


what that worked for me:

go to the fodler

C:\Users\{YOUR PC USER NAME}\AppData\Local\Programs\Python\Python37-32\Lib\site-packages 

and either delete or change the name of the PIL folder and DONE.

had to do it after running

pip uninstall PIL

as other suggested yielded for me

WARNING: Skipping PIL as it is not installed.

But I am not sure about the consequences of removing that library so I will edit this post if I ever get into a problem because of that.


All the answers were great however what did it for me was a combination of uninstalling Pillow

pip uninstall Pillow

Then installing whatever packages you need e.g.

sudo apt-get -y install python-imaging
sudo apt-get -y install zlib1g-dev
sudo apt-get -y install libjpeg-dev

And then using easy_install to reinstall Pillow

easy_install Pillow

Hope this helps others


Now, I actually did some debugging with my brother and found that Pillow (PIL) needed to be initialized. I don't know how to initialize it, so you could probably stick with reinstalling Pillow.


Try import PIL instead of from PIL import image.


FWIW, the following worked for me when I had this same error:

pip install --upgrade --force-reinstall pillow

For me, I had typed image with a lower case "i" instead of Image. So I did:

from PIL import Image NOT from PIL import image


The current free version is PIL 1.1.7. This release supports Python 1.5.2 and newer, including 2.5 and 2.6. A version for 3.X will be released later.

Python Imaging Library (PIL)

Your python version is 3.4.1, PIL do not support!


I had the same problem, pillow was installed with an environment.yml in anaconda

I am quickly learning that pip and setuptools must always be up to date or I will have problems. Always update these tools before installing packages.For any package import problem uninstall the package upgrade the listed tools(maybe even your base environment) and reinstall.

conda uninstall pillow
python -m pip install pip --upgrade
pip install setuptools --upgrade
pip install pillow

If using Anaconda, from the base environment first run the following before installing packages/environments:

conda update conda

Updating the base env is not required to fix this issue but is a good practice to avoid similar problems

@theeastcoastwest touched on the pip upgrade in their answer but I felt more information was needed


had the same error while using pytorch code which had deprecated pillow code. since PILLOW_VERSION was deprecated, i worked around it by:

Simply duplicating the _version file and renaming it as PILLOW_VERSION.py in the same folder.

worked for me


If you did all and it didn't work again like mien, do this copy Image.py and ImageTk.py from /usr/lib/python3/dist-packages/PIL on ubuntu and C:/Users/yourComputerName/AppData/Local/Programs/Python/Python36/Lib/PIL on windows to your projects directory and just import them!


do from PIL import Image, ImageTk


If you use Anaconda, you may try:

conda install Pillow

Example


Any library/package you import must have its dependencies and subordinate parts in the same python directory. in linux if you

Python3.x -m pip install <your_library_name_without_braces>

what happens is, it installs on the default python. so first make sure that only 1 python 2.x and 1 python 3.x versions are on your pc.

If you want to successfully install matplotlib you need these lines,

python -m pip install matplotlib pillow numpy pandas

the last 2 were auxiliary libs, and must have.


Install Pillow from Command Line:

python -m pip install pillow

Examples related to python

programming a servo thru a barometer Is there a way to view two blocks of code from the same file simultaneously in Sublime Text? python variable NameError Why my regexp for hyphenated words doesn't work? Comparing a variable with a string python not working when redirecting from bash script is it possible to add colors to python output? Get Public URL for File - Google Cloud Storage - App Engine (Python) Real time face detection OpenCV, Python xlrd.biffh.XLRDError: Excel xlsx file; not supported Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation

Examples related to python-imaging-library

How do I install PIL/Pillow for Python 3.6? TypeError: Image data can not convert to float Combine several images horizontally with Python Generate random colors (RGB) How to show PIL Image in ipython notebook Why can't Python import Image from PIL? Importing images from a directory (Python) to list or dictionary ImportError: No module named Image Installing PIL with pip Image.open() cannot identify image file - Python?

Examples related to importerror

ImportError: libSM.so.6: cannot open shared object file: No such file or directory "ImportError: no module named 'requests'" after installing with pip ImportError: cannot import name main when running pip --version command in windows7 32 bit Why can't Python import Image from PIL? ImportError: No module named 'bottle' - PyCharm Installing OpenCV for Python on Ubuntu, getting ImportError: No module named cv2.cv How can I troubleshoot Python "Could not find platform independent libraries <prefix>" "ImportError: No module named" when trying to run Python script ImportError: DLL load failed: %1 is not a valid Win32 application ImportError: No module named six

Examples related to python-import

Python: 'ModuleNotFoundError' when trying to import module from imported package ImportError: libSM.so.6: cannot open shared object file: No such file or directory Relative imports - ModuleNotFoundError: No module named x ModuleNotFoundError: What does it mean __main__ is not a package? Reading file using relative path in python project What does from __future__ import absolute_import actually do? Why does using from __future__ import print_function breaks Python2-style print? Automatically create requirements.txt Error importing Seaborn module in Python Why can't Python import Image from PIL?

Examples related to pillow

How do I install PIL/Pillow for Python 3.6? Fail during installation of Pillow (Python module) in Linux Why can't Python import Image from PIL? Python Image Library fails with message "decoder JPEG not available" - PIL