75

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?

Betohaku
  • 865
  • 1
  • 6
  • 9
  • 1
    perhaps try a reinstall? Or have a look int the Image.py source and you might see what's causing the issue.. – Totem Oct 22 '14 at 11:06
  • @Totem Tried the reinstall, did nothing. I do see the line (29) in the source, but have no idea how it causes an issue. – Betohaku Oct 22 '14 at 11:26
  • Can you check that `C:\pyzo2014a\lib\site-packages\PIL\__init__.py` contains constants like `VERSION`, `PILLOW_VERSION` etc? For the record, my `__init__.py` is 58 lines long, same (2.6.1) Pillow version. –  Oct 22 '14 at 12:42
  • @Evert Lines 14 and 15 are `VERSION = '1.1.7'` and `PILLOW_VERSION = '2.6.1'`, these seem to be the only constants. 58 lines here as well. – Betohaku Oct 22 '14 at 13:08
  • Then I think it's likely python still picks up another `PIL` on your `PYTHONPATH`. Try something like `python3.4 -c "import PIL; print(PIL.__file__)"`. –  Oct 22 '14 at 13:28
  • @Evert Running `import PIL; print(PIL.__file__)` in Pyzo gives `C:\pyzo2014a\lib\site-packages\PIL\__init__.py`. That's what it's supposed to be, right? CMD doesn't recognise the `python3.4` in front of it btw. – Betohaku Oct 22 '14 at 13:37
  • Looks ok indeed; I can't think what's wrong, unless it's Pyzo messing around, but I don't know Pyzo. The `python3.4 -c` part was just copy-paste from my cmdline, no worries. –  Oct 22 '14 at 13:50
  • Can you run the script outside of your Pyzo environment? –  Oct 22 '14 at 13:58
  • @Evert Running it in IDLE, I get an error instead of the path: `ImportError: No module named PIL`. – Betohaku Oct 22 '14 at 14:08
  • In IDLE, it's just a `PYTHONPATH` issue. But you should really try from the command prompt, provided you've set your PYTHONPATH correctly before that. –  Oct 22 '14 at 14:33
  • @Evert Pardon my stupidity, but what should be typed into the command prompt then? And how can one 'set' PYTHONPATH? – Betohaku Oct 22 '14 at 14:39
  • I'm voting to close this question as off-topic because installation questions are off-topic. [Can I ask questions about installation in SO?](https://meta.stackoverflow.com/questions/338203/can-i-ask-questions-about-installation-in-so) Software tools commonly used by programmers and is **a practical, answerable problem that is unique to software development.** – Trenton McKinney Oct 08 '19 at 03:14

19 Answers19

70

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
Munim Munna
  • 17,178
  • 6
  • 29
  • 58
Trent
  • 2,122
  • 1
  • 24
  • 38
25

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.

Community
  • 1
  • 1
Nijanth Anand
  • 261
  • 3
  • 2
24

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

pip install --upgrade --force-reinstall Pillow
Michael Currie
  • 13,721
  • 9
  • 42
  • 58
alphazwest
  • 3,483
  • 1
  • 27
  • 39
13

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

WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560
alkadelik
  • 526
  • 1
  • 7
  • 18
12

If you use Anaconda, you may try:

conda install Pillow

Example

Matteo Baldi
  • 5,613
  • 10
  • 39
  • 51
Ruikai H
  • 121
  • 1
  • 2
6

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

Artisan
  • 1,974
  • 1
  • 18
  • 23
5

Install Pillow from Command Line:

python -m pip install pillow
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Vatsala Jha
  • 51
  • 1
  • 3
3

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!

selfboot
  • 1,490
  • 18
  • 23
2

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 ;-)

Vivien G.
  • 79
  • 4
1

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

1

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

dpoiesz
  • 113
  • 1
  • 8
1

If you've got different Python versions, be sure to install it with the version, you start the script:

python3.9 -m pip install pillow --upgrade

After a lot of googling and different solutions, this is the most efficient, I found.

rundekugel
  • 1,118
  • 1
  • 10
  • 23
1

I am also facing same error, just try to uninstall and resinstall

#uninstall and resinstalltion cmds
pip uninstall pillow
pip uninstall PIL
pip install pillow

Pillow installation link basics link

Using jupyter note book do this below follwing installationa and verified the code as shown below

pip install pillow

#(or)

pip install PIL

import PIL
print(PIL.__version__)

'8.4.0'

(Or) You are using command prompt installation then follow below instruction for windows. Personally suggest this below method.

Microsoft Windows [Version 10.0.19043.1348]
(c) Microsoft Corporation. All rights reserved.

>pip install pillow
Requirement already satisfied: pillow in c:\users\admin\appdata\roaming\python\python310\site-packages (9.0.0)

>python
Python 3.10.1 (tags/v3.10.1:2cd268a, Dec  6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL
>>> (PIL.__version__)
'9.0.0'
>>> quit()
0

do from PIL import Image, ImageTk

Guydangerous99
  • 147
  • 1
  • 12
0

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!

0

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.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
nikhil swami
  • 2,360
  • 5
  • 15
0

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.

coder
  • 700
  • 8
  • 12
0

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.

-5

Try import PIL instead of from PIL import image.

Rishabh Agarwal
  • 1,988
  • 1
  • 16
  • 33
kab
  • 1