Why can't Python import Image from PIL? - python
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?
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:
In command prompt
pip install Pillow ##
Ensure that you use
from PIL import Image
I in Image has to be capital. That was the issue in my case.
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
If you use Anaconda, you may try:
conda install Pillow
Example
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
Install Pillow from Command Line:
python -m pip install pillow
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!
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 ;-)
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
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
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.
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()
do from PIL import Image, ImageTk
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!
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.
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.
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.
Related
pillow installation error in vs when using djngo
ERRORS: core.Item.image: (fields.E210) Cannot use ImageField because Pillow is not installed. HINT: Get Pillow at https://pypi.org/project/Pillow/ or run command "pip install Pillow". since I was installed pillow when I run the pip install pillow command It shows the requirement already satisfied. please give me a solution
This can happen because you have PIL and Pillow installed. Pillow is a fork of PIL and is the maintained library. It is recommended not to use PIL because it has become outdated. Here are the steps to fix the problem: pip uninstall PIL pip uninstall pillow then: pip install pillow If this doesn't solve the problem, go into your python site-packages or dist-packages and remove any files or folders related to PIL or pillow, then: pip install pillow
Django says Pillow is not installed even though it is
I keep getting the same error when I try to run manage.py runserver: Cannot use ImageField because Pillow is not installed. I have seen several threads made by people that have encountered the same problem but none of them have a straightforward fix to this issue. I have already installed Pillow (pip install Pillow and pip3 install Pillow). I have uninstalled it several times, and reinstalled it. But whenever I run my server it says that Pillow is not installed. I am on Windows 10. Any help would be appreciated. FIXED! I removed all paths and made two new ones in my environment variables. It works now.
Try this to install or if you have already try to upgrade python3 -m pip install --upgrade pip python3 -m pip install --upgrade Pillow try importing package like this.. >>> from PIL import Image Refer to official docs
How to Upgrade OpenCV to Specific Version Using Pip?
I want to install OpenCV 3.4.0 on Ubuntu 16.04. I tried to build from source following tutorial on internet but run to this problem: ImportError: /home/ivan/.virtualenvs/cv/lib/python3.5/site-packages/cv2.so: undefined symbol: _ZTIN2cv3dnn19experimental_dnn_v35LayerE So I decided to just upgrade OpenCV using pip following solution on github https://github.com/CharlesShang/FastMaskRCNN/issues/111: pip3 install --upgrade opencv-python It works fine, cv2 successfully imported. But it directly upgraded to opencv 4.0.0 . Is there any way to upgrade opencv to specific version (ex: 3.4.0) using pip?
All you have to do is to put the version in the command as follows pip3 install --upgrade opencv-python==3.4.0
Actually (in 2020) Opencv library is version 4.2.XX so my suggestion: pip3 install --upgrade opencv-python==4.2.34
python PIL installation on python 3.6
I have tried to install PIL, however unsuccessfully. I used the commands: pip install pillow sudo pip3 install pillow And yet python didn't recognize PIL. Any solutions to this problem ?
You might be having PIL already installed which may be conflicting. Go to your python packages and manually delete pillow, Pillow, PIL etc and reinstall using pip install pillow
You say that it worked once and then later does not. A mistake that I have made more than once is naming a script that I am writing pil.py, and then wondering why I can't import PIL. So that could be an explanation. If the installation is truly the problem though, here are some alternatives. You could try python3.6 -m pip install Pillow - it does the same thing, but you never know. You could try downloading the source code of Pillow - https://github.com/python-pillow/Pillow/releases - and running python3.6 setup.py install to install it directly. This will likely fail to lack of other requirements, but again, just giving ideas. If you're on Linux, you could try your relevant package manger - apt install python3-pil for Ubuntu, etc.
Can't install PIL after Mac OS X 10.9
I've just updated my Mac OS to 10.9 and I discovered that some (all?) of my Python modules are not here anymore, especially the Image one. So I try to execute sudo pip install pil, but I get this error: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/tk.h:78:11: fatal error: 'X11/Xlib.h' file not found # include <X11/Xlib.h> ^ 1 error generated. error: command 'cc' failed with exit status 1 My Xcode is up-to-date and I don't have any idea. Is it possible that PIL is not yet 10.9 compatible ?
Following worked for me: ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11 /usr/local/include/X11 sudo pip install pil UPDATE: But there is more correct solution below, provided by Will. open your terminal and execute: xcode-select --install
open your terminal and execute: xcode-select --install
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11/ /usr/local/include/X11 helps for me! os x 10.9 pip install pillow but! after pip install ... *** ZLIB (PNG/ZIP) support not available and finally i fix it by running: xcode-select --install then reinstall pillow pip install pillow PIL SETUP SUMMARY -------------------------------------------------------------------- version Pillow 2.2.1 platform darwin 2.7.5 (default, Aug 25 2013, 00:04:04) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] -------------------------------------------------------------------- --- TKINTER support available --- JPEG support available --- ZLIB (PNG/ZIP) support available --- TIFF G3/G4 (experimental) support available --- FREETYPE2 support available --- LITTLECMS support available --- WEBP support available --- WEBPMUX support available --------------------------------------------------------------------
Works for me ( OS X Yosemite 10.10.2 - Python 2.7.9 ) : xcode-select --install sudo pip install pillow Try this to check it: from PIL import Image image = Image.open("file.jpg") image.show()
Here is what I did, some steps may not be necessary just for PIL but I needed libpng and others anyways: 1) Run xcode install, use this command or download updates from the app store: xcode-select --install 1b) Add the Command Line Tools optional tool, in Mountain Lion this was an option on the xcode Download page, but now you have to register with your apple id and download from: https://developer.apple.com/downloads/ Look for Command Line Tools (OS X Mavericks) for Xcode 2) Install everything needed for python (using brew), I believe you can use port as well: brew install readline sqlite gdbm brew install python --universal --framework brew install libpng jpeg freetype Unlink/ relink if needed i.e. if upgrading. 3) Install Pip and required modules: easy_install pip sudo pip install setuptools --no-use-wheel --upgrade 4) Finally this works with no errors: sudo pip install Pillow UPDATE 11/04/14: PIL repo no longer receives updates or support so Pillow should be used. The below is now deprecated so stick with Pillow. sudo pip install pil --allow-external pil --allow-unverified pil UPDATE (OLD) : The same thing applies when installing Pillow (PIL fork) and should be mentioned as its quickly becoming a replacement in most cases of PIL. Instead of installing pip in step 4, run this instead: sudo pip install Pillow Hope this helps someone!
installing command line tools fixed the issue for me you have to install them separately as they are not part of the packages in xcode now: https://developer.apple.com/downloads/index.action?=command%20line%20tools#
Non of those worked for me.. I kept receiving: clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future] clang: note: this will be a hard error (cannot be downgraded to a warning) in the future error: command 'cc' failed with exit status 1 So I found a work around with the following solution: sudo export CFLAGS=-Qunused-arguments sudo export CPPFLAGS=-Qunused-arguments sudo pip install PIL --allow-external PIL --allow-unverified PIL This way I was able to install.
I had a similar problem: Installing pillow failed with clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future], installing command line tools failed with Can't install the software because it is not currently available from the Software Update server., and even after installing the command line tools manually, the compilation of PIL failed. This happens cause clang under the newest version of xcode doesn't warn on unknown compiler flags, but rather stop the compilation with a hard error. To fix this, just run export ARCHFLAGS="-Wno-error=unused-command-line-argument-hard-error-in-future" on the terminal before trying to compile (installing pil).
Simply run pip install pil --allow-external pil --allow-unverified pil
This my steps on mac os 10.9.1 1. sudo su 2. easy_install pip 3. xcode-select --install 4. pip install --no-index -f http://dist.plone.org/thirdparty/ -U PIL
You could use Homebrew to do the install http://brew.sh brew tap Homebrew/python brew install pillow
Make sure you have Command Line Tools installed on your xcode. Then execute: sudo pip install pil --allow-external pil --allow-unverified pil
I was having the following error building 'PIL._imagingft' extension _imagingft.c:62:10: fatal error: 'freetype/fterrors.h' file not found #include <freetype/fterrors.h> ^ 1 error generated. error: command 'cc' failed with exit status 1 The solution to this was to symlink freetype2 to freetype and this solved the problem.
I didn't want to install XCode (I don't use it) and I'm loath to fiddle with Application directory. I've cribbed from the many answers in this post and the following two steps work for me with 10.9.5: sudo easy_install pip sudo pip install pillow It did appear to me strange that I had to use easy_install to install pip. But pip didn't want to work for me before that (re-)install.
Found the solution ... You've to symlink X11 like this ln -s /opt/X11/include/X11 /usr/local/include/X11 and then sudo pip install pil should work.
Reusing #DmitryDemidenko's answer that is how it worked for me: ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11 /usr/local/include/X11 and then sudo pip install -U PIL --allow-external PIL --allow-unverified PIL
Execute the bellow command lines. Works like a charm on Mac OS 10.9.5 easy_install pip sudo pip install setuptools --no-use-wheel --upgrade sudo pip install Pillow Best, Theo
That's what I did: First upgrade to Xcode 5 (I am running 10.9). Then, execute the following commands in a terminal: $ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk $ ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11 usr/include/
A more complete solution requires the installation of the Xquartz X11 subsystem that has been built outside of Apple for several years now. Here are the steps I used to get it all working Install XQuartz from http://xquartz.macosforge.org/landing/ Run sudo pip install pillow
As the accepted answer is the right one with xcode-select --install but some people (including me) may encounter Can't install the software because it is not currently available from the Software Update server If you are using beta software (as I am using Yosemite now and had the same problem) you NEED to get the CLT separately since it is NOT included in XCode (even xcode beta) Head over to developers.apple.com and get CLT tools for your OS ;) P.S. You don't need XQuartz for PIL or Pillow to work
My machine which was recently upgraded from OS 10.8 -> 10.9 got stuck in a loop between xcrun and lipo. Rename /usr/bin/lipo to /usr/bin/lipo_broken Refer to this thread for further information on how to resolve: xcrun/lipo freezes with OS X Mavericks and XCode 4.x
Install Pillow instead: sudo pip install pillow
ln -s /usr/local/include/freetype2 /usr/local/include/freetype sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install pil
Try this: ln -s /usr/local/include/freetype2 /usr/local/include/freetype
sudo pip uninstall pillow pip install pillow worked for me. I'm running Python 2.7.9 on Yosemite.import PIL now works for me.
Installing PIL (Imaging.1.1.7) on Mac OSC 10.10 Yosemite. I tried numerous fixes recommended here but ran into trouble with each one. I finally solved this problem by editing the setup.py file such that: TCL_ROOT = "/opt/X11/include" which passes the appropriate include path for X11 in the compilation of _imagingtk.c, which was causing the problem for me. Worked immediately after change.
I've moved from pyenv to virtualenv and this fixed my problem.
ln -s /opt/X11/include/X11 /usr/local/include/X11 pip install pil without sudo