Fix Python ModuleNotFoundError: No module named ‘PIL’
Posted on Feb 08, 2023
If you use the Python Imaging Library (PIL) in your code, you might encounter this error:
This error occurs when you try to import the PIL module without installing the Pillow package.
If you already have the Pillow package, then you may have multiple versions of Python installed on your computer, and Python is looking at the wrong folder for the package.
This article shows examples that cause the error and how to fix it.
1. Install the Pillow library
The PIL package has been forked to the Pillow package, so to import PIL in your code, you need to install Pillow .
First, you need to uninstall PIL because Pillow and PIL cannot co-exist in the same environment:
Once you installed Pillow, you can import PIL with the following code:
Please note that you can’t use import PIL or import Image . The latest Pillow version requires you to state the import exactly as from PIL import Image .
If you use the module like this:
You’ll get the following error:
You also need to replace import _imaging as shown below:
Now that you have Pillow installed, you should be able to use PIL without any errors.
If that doesn’t work, then you might have multiple Python versions installed on your computer.
2. Check if you have multiple Python versions installed
If you have multiple versions of Python installed on your system, you need to make sure that you are using the specific version where the pillow module is installed.
You can test this by running the which -a python and which -a python3 commands from the terminal:
- Python 2 installed on /usr/local/bin/python
- Python 3 installed on /usr/local/bin/python3 and /usr/bin/python3
Each Python distribution is bundled with a specific pip version. If you want to install a module for Python 2, use pip . Otherwise, use pip3 for Python 3.
The problem arise when you install pillow for Python 2 but runs the code using Python 3, or vice versa:
If you install Pillow for Python 2, then you need to run the code using Python 2 as well:
Having multiple Python versions can be confusing, so you need to carefully inspect how many Python versions you have on your computer.
3. No module named PIL in Visual Studio Code (VSCode)
If you use VSCode integrated terminal to run your code, you might get this error even when Pillow is already installed.
This means the Python and pip versions used by VSCode differ from the one where you install Pillow.
You can check this by running the following code:
The print output will show you the absolute path to the Python used by VSCode. For example:
Copy the path shown in the terminal and add -m pip install pillow as follows:
This will install pillow for the Python interpreter used by VSCode. Once finished, try running your code again. It should work this time.
Conclusion
Most likely, you see the No module named PIL error because you didn’t install the pillow package from pip , or you installed the package on a different version of Python.
The steps shown in this article should help you fix this error.
I hope this article is helpful. Happy coding!
Take your skills to the next level ⚡️
I’m sending out an occasional email with the latest tutorials on programming, web development, and statistics. Drop your email in the box below and I’ll send new stuff straight into your inbox!
About
Hello! This website is dedicated to help you learn tech and data science skills with its step-by-step, beginner-friendly tutorials.
Learn statistics, JavaScript and other programming languages using clear examples written for people.
Search
Type the keyword below and hit enter
ModuleNotFoundError: No module named ‘PIL’ в чем проблема?
def download(query: str, page_count: int) -> None:
header =
params =
url = f»https://api.pexels.com/v1/search»
i = 1
while i params[«page»] = i
r = requests.get(url, headers=header, params=params)
if r.status_code == 200:
_r = r.json()
for item in _r.get(«photos»):
_img_url = item.get(«src»).get(«original»)
resp = requests.get(_img_url)
image = Image.open(BytesIO(resp.content))
image.save(f»media/_.»)
else:
print(r.text)
i += 1
def main() -> None:
query = input(«Query «)
page_count = int(input(«Count page «))
download(query, page_count)
- Вопрос задан более двух лет назад
- 228 просмотров
1 комментарий
Простой 1 комментарий
Modulenotfounderror: no module named pil ( Solved )
Modulenotfounderror: no module named pil error occurs if the pillow package is not installed or not properly configured. The best way to resolve this error is to reinstall the pillow module again. In some of the cases, the same error occurs because of importing the PIL module in the place of the image module. In this article, we will see the different easiest ways to install pillow modules. Also, we will address the import issue. So let’s start.
What is the Pillow (pil ) Python module?
The pillow module allows you to manipulate and save images in different file formats like JPEG, PNG, BMP, GIF, TIFF, and others. You can perform many operations like cropping, resizing, rotating, color conversions, and more. You can also do image processing operations like filtering and enhancing. In addition, it allows you to add watermarks or captions to the images.
Modulenotfounderror: no module named pil ( Solution )-
The best and easiest way to install any python package is using any package manager either pip, conda, or some other like easy_install. Here in a single line command we can install any python package.
Solution 1: pip for pillow installation –
Use this command to install the pillow with the pip package manager.
pip install Pillow
We can install any version of the pillow by just adding the version in the pillow command. For version, detail refers to the release details of pillow.
pip install Pillow==9.2.0
For admin rights please add sudo keyword in Linux similar OS and In windows, launch the cmd in Admin mode. If you are getting permission issues.
If pip is not properly configured then run the below command.
python -m pip install Pillow
Solution 2: conda for pillow installation –
conda comes with Anaconda distribution.
conda install -c conda-forge pillow
Here we can change the mirrors just like in the above command we are using conda-forge mirror we can use the below mirror as well.
Solution 3: Source for pillow installation –
Here we will build pillow packages locally. For this, we need to download the source code for the pillow package and then run the
ImportError: No module named PIL
@RikPoggi This page of documentation actually tells to use from PIL import Image , which does not work.
May 4, 2012 at 7:30
@Janne just use Import Image,and PIL starts working.
May 11, 2012 at 9:40
At this time I’d recommend to easy_install Pillow instead. Pillow is a fork of PIL that has better packaging and supports Python 3.
Jul 23, 2013 at 10:48
Can you change the accepted answer to one that recommends Pillow? As @LennartRegebro said, this package is better long-term.
Aug 28, 2019 at 20:44
Use pip install Pillow instead. Then you can do import PIL.Image
Jan 27, 2021 at 8:54
30 Answers 30
pip install Pillow
Attention: PIL is deprecated, and pillow is the successor.
377k 47 47 gold badges 452 452 silver badges 637 637 bronze badges
answered Mar 28, 2014 at 20:49
zhiming wang zhiming wang
4,949 2 2 gold badges 11 11 silver badges 2 2 bronze badges
Really? image is not the PIL module of the question, it’s instead a «Django application» (that happens to be based on PIL). Reference: github.com/francescortiz/image.
Jan 21, 2017 at 18:30
pip install image worked for me. thanks to duckduckgo cache for holding onto pre-edit answer!
Sep 15, 2018 at 22:01
I’ve seen PILLOW other places, Pillow here. cmd is not case-sensitive, but what is the preferred way of writing this?
Aug 28, 2019 at 20:43
installing image with that weird django thing got this script i found to run at least. It didn’t get far enough to test the package though.
Sep 19, 2019 at 0:59
When I key «pip install Pillow» in Terminal, it appears this error: Requirement already satisfied: Pillow in c:\users\user\venv\odoo\lib\site-packages (6.2.2)
May 22, 2020 at 14:44
On some installs of PIL, you must do
import Image
instead of import PIL (PIL is in fact not always imported this way). Since import Image works for you, this means that you have in fact installed PIL.
Having a different name for the library and the Python module is unusual, but this is what was chosen for (some versions of) PIL.
You can get more information about how to use this module from the official tutorial.
PS: In fact, on some installs, import PIL does work, which adds to the confusion. This is confirmed by an example from the documentation, as @JanneKarila found out, and also by some more recent versions of the MacPorts PIL package (1.1.7).
answered Jan 14, 2012 at 17:36
Eric O. Lebigot Eric O. Lebigot
91.9k 48 48 gold badges 219 219 silver badges 261 261 bronze badges
pip install image from Zhiming’s answer worked for me.
Oct 14, 2015 at 22:42
yup, @JimSchubert said it. pip install image from @zhimmingwang worked for me too
Nov 4, 2015 at 14:04
But image is not PIL (as in the question), it’s a different module. Reference: github.com/francescortiz/image. Am I missing something, here?
Jan 21, 2017 at 18:31
I got the same error «ImportError: No module named PIL». Installed Pillow with «pip install Pillow» and tried to run the script. Still got the same error. Then, I tried to import an image, it says ‘No module named image’ found. I installed image using ‘pip install image’ and tried again. No luck. Any suggestions?
– user3252885
Oct 11, 2017 at 15:47
You should check that your pip installs for the python interpreter that you are using. pip -V tells you where it installs. Under Unix, which python tells you where your python command is. The two should match well enough. Or, better: python -c ‘import sys; print sys.path’ will tell you where your python command looks for modules ( print(sys.path) , for Python 3).
Oct 26, 2017 at 8:34
On a different note, I can highly recommend the use of Pillow which is backwards compatible with PIL and is better maintained/will work on newer systems.
When that is installed you can do
import PIL
from PIL import Image
1,127 10 10 silver badges 20 20 bronze badges
answered Jul 23, 2013 at 9:24
2,608 24 24 silver badges 19 19 bronze badges
None of the other answers fixed the issue I had, but this one did.
Dec 7, 2017 at 13:49
The second one no longer works. pillow.readthedocs.io/en/stable/installation.html
Oct 18 at 0:10
At first install Pillow with
pip install Pillow
c:\Python35>python -m pip install Pillow
Then in python code you may call
from PIL import Image
«Pillow is a fork of PIL, the Python Imaging Library, which is no longer maintained. However, to maintain backwards compatibility, the old module name is used.» From pillow installed, but «no module named pillow» — python2.7 — Windows 7 — python -m install pillow
1 1 1 silver badge
answered Feb 14, 2016 at 18:24
Orhan Celik Orhan Celik
1,533 15 15 silver badges 12 12 bronze badges
i am getting Requirement already satisfied but still the same issue
Jun 3, 2016 at 4:49
Sometimes I get this type of error running a Unitest in python. The solution is to uninstall and install the same package on your virtual environment.
Using this commands:
pip uninstall PIL
pip install PIL
If for any reason you get an error, add sudo at the beginning of the command and after hitting enter type your password.
73.8k 37 37 gold badges 152 152 silver badges 186 186 bronze badges
answered Feb 25, 2013 at 15:01
Fernando Munoz Fernando Munoz
4,631 2 2 gold badges 18 18 silver badges 16 16 bronze badges
This also works for me. Consider that one might use other Python scripts that indirectly uses PIL, changing the Import statement is not always an option.
Jul 25, 2013 at 22:28
This didn’t work for me, it couldn’t find a repository called PIL (or pil). However I ran «pip install Pillow» which did work. My understanding is that Pillow is a branch of PIL.
Oct 30, 2014 at 16:54
@TeeBasins Pillow is the “friendly PIL fork” by Alex Clark and Contributors.
– user4396006
Jul 6, 2015 at 9:47
I get » Could not find a version that satisfies the requirement PIL (from versions: ) No matching distribution found for PIL»
May 21, 2018 at 1:07
This worked for me but after I updated the pip installer. To update, run: python.exe -m pip install —upgrade pip —> pip uninstall Pillow —-> pip install Pillow
Sep 13 at 7:41
This worked for me on Ubuntu 16.04:
sudo apt-get install python-imaging
I found this on Wikibooks after searching for about half an hour.
answered Nov 17, 2016 at 14:56
grooveplex grooveplex
2,493 4 4 gold badges 28 28 silver badges 30 30 bronze badges
This question was asked before the Ubuntu 16.04, but I met this problem in Ubunt 16.04 and fixed it with your suggestion.
Jan 13, 2017 at 3:21
Glad I could help! 😀
Jan 13, 2017 at 11:00
This was my issue on a RPI with an OLED screen displaying python output
Mar 4, 2019 at 0:37
This fixed my issue with Pillow but my actual problem was that python 2 was used when I typed python in the command line instead of python3 (you can check for this with python -V )
Dec 9, 2021 at 21:26
you have to install Image and pillow with your python package.
python -m pip install image
or run command prompt (in windows), then navigate to the scripts folder
cd C:\Python27\Scripts
then run below command
pip install image
answered Jan 2, 2018 at 13:18
1,229 9 9 silver badges 17 17 bronze badges
For python3 use python3 -m pip install Pillow
Jun 23, 2021 at 15:59
Uninstalling Pillow and then installing image worked for me.
Oct 27, 2021 at 18:03
On windows 10 I managed to get there with:
cd "C:\Users\\AppData\Local\Programs\Python\Python37-32" python -m pip install --upgrade pip
after which in python (python 3.7 in my case) this works fine.
import PIL from PIL import image
answered Aug 20, 2019 at 20:11
andrew pate andrew pate
3,881 37 37 silver badges 29 29 bronze badges
After upgrading windows 7 to windows 10 my python program didn't work but this method solved it. Thanks!
Dec 16, 2019 at 10:20
pip install Pillow
and pip installed PIL in Lib\site-packages. When I moved PIL to Lib everything worked fine. I'm on Windows 10.
answered Aug 5, 2019 at 0:45
181 1 1 silver badge 4 4 bronze badges
Install Specific Version:
pip install Pillow
sudo pip3 install --upgrade Pillow
Getting Dependency Error in Window 10 Use code: easy_install instead of pip install
easy_install Pillow
Upgrade using easy install
sudo easy_install --upgrade Pillow
On OSX System to install Module: Use code: brew install instead of pip install
brew install Pillow
Without Using Pip :
sudo apt-get install -y Pillow
On CentOS7 or Linux Fedora:
yum -y install Pillow
Or on Fedora try
sudo dnf install Pillow
Command if Homebrew screws up your path on macOS:
python -m pip install Pillow
For Python3 MacOs Homebrew screws
python3 -m pip install Pillow
Verify module from list MacOs
pip freeze | grep Pillow
For Execute on Anaconda as your python package manager
conda install -c anaconda Pillow
answered Mar 27, 2021 at 7:33
Shantanu Bombatkar Shantanu Bombatkar
155 1 1 silver badge 2 2 bronze badges
upgrading the Pillow did it for me on windows11
Aug 27, 2022 at 16:25
On windows, try checking the path to the location of the PIL library. On my system, I noticed the path was
\Python26\Lib\site-packages\pil instead of \Python26\Lib\site-packages\PIL
after renaming the pil folder to PIL , I was able to load the PIL module.
5,278 43 43 gold badges 65 65 silver badges 115 115 bronze badges
answered Apr 4, 2013 at 11:08
91 1 1 silver badge 1 1 bronze badge
I was also getting same import error. I have installed PIL using easy_install. In site-packages it was installed in directory with 'PIL-1.1.7-py2.7-win32.egg' name. As per your suggestion i have changed the dir name to PIL and it worked. Thanks for your help @Komla.
Feb 25, 2014 at 5:42
if you use anaconda:
conda install pillow
answered Jan 10, 2018 at 23:02
1,156 1 1 gold badge 15 15 silver badges 20 20 bronze badges
I did this, it still couldnt import PIL
Aug 22, 2019 at 5:19
@johnktejik which version of Python and Anaconda are you using?
Aug 25, 2019 at 18:38
The cleanest way to resolve this issue is by following below steps.
Step 1: Uninstall the PIL package.
pip uninstall PIL
Step 2: Install the Pillow using pip as shown below on windows operating systems. For other environments checkout the article No module named PIL
python3 -m pip install --upgrade pip python3 -m pip install --upgrade Pillow
Step 3: The most crucial class in the Python Imaging Library is the Image class, and you can import this as shown below.
from PIL import Image im = Image.open("myimage.jpg")
If successful, this function returns an Image object. You can now use instance attributes to examine the file contents:
print(im.format, im.size, im.mode) #Output: PPM (512, 512) RGB
answered Dec 9, 2021 at 18:25
Srinivas Ramakrishna Srinivas Ramakrishna
1,304 13 13 silver badges 21 21 bronze badges
This has worked for me on windows 11.
Feb 9 at 11:28
This worked for me on macOS Monterey, after every other face_recognition/dlib install python fix failed. I needed to downgrade to py 3.9 from 3.11 tho.
Mar 12 at 23:05
I had the same issue on windows 10 and this worked for me:
answered Mar 7, 2022 at 8:51
Cyebukayire Cyebukayire
855 8 8 silver badges 14 14 bronze badges
You will need to install Image and pillow with your python package. Rest assured, the command line will take care of everything for you.
python -m pip install image
answered May 10, 2017 at 8:43
Dipanshu Sehjal Dipanshu Sehjal
79 1 1 silver badge 4 4 bronze badges
instead of PIL use Pillow it works
easy_install Pillow
pip install Pillow
answered Apr 13, 2018 at 5:21
14.1k 3 3 gold badges 85 85 silver badges 54 54 bronze badges
pip(3) uninstall Pillow pip(3) uninstall PIL pip(3) install Pillow
answered Oct 15, 2020 at 16:34
787 8 8 silver badges 15 15 bronze badges
This worked for me on Ubuntu 20.04 :
pip install image
import image
answered Sep 24, 2022 at 13:33
MD. Mohiuddin Ahmed MD. Mohiuddin Ahmed
2,112 2 2 gold badges 27 27 silver badges 35 35 bronze badges
use pil instead of PIL
from pil import Image
answered Sep 5, 2020 at 13:58
787 8 8 silver badges 15 15 bronze badges
On Windows, you need to download it and install the .exe
answered Aug 18, 2016 at 13:43
user285594 user285594
I used conda-forge to install pillow version 5, and that seemed to work for me:
conda install --channel conda-forge pillow=5
the normal conda install pillow did NOT work for me.
answered Jul 10, 2018 at 16:06
Geoff Perrin Geoff Perrin
444 1 1 gold badge 6 6 silver badges 14 14 bronze badges
I had the same problem and i fixed it by checking what version pip ( pip3 --version ) is, then realizing I'm typing python filename.py instead of python filename.py
answered Dec 23, 2018 at 23:24
Ori Barmatz Ori Barmatz
41 1 1 silver badge 5 5 bronze badges
from pil import Image
from PIL import Image
and it worked for me fine
answered Jul 20, 2020 at 10:12
137 1 1 silver badge 8 8 bronze badges
I found an easier solution. Use a virtual environment.
pip install Pillow
from PIL import Image
This works for me on a macOS
answered Oct 31, 2021 at 21:14
182 1 1 silver badge 12 12 bronze badges
I had the same issue while importing PIL and further importing the ImageTk and Image modules. I also tried installing PIL directly through pip. but not success could be achieved. As in between it has been suggested that PIL has been deprectaed, thus, tried to install pillow through pip only. pillow was successfully installed, further, the PIL package was made under the path : python27/Lib/site-packages/.
Now both Image and ImageTk could be imported.
answered May 25, 2015 at 16:47
Prateek Jain Prateek Jain
I recently installed Leap. I Tried openshot and it didn't start. So came here and found a suggestion to start from the Terminal to see if there were any error.
The error I had was error missing mlt . So I installed the python-mlt module from Yast and imported it, tried to start but next openshot said missing pil.
I Followed the Pillow suggestion to install because Yast couldn't find any pil and imported pil. That went ok but did not start and showed Error missing goocanvas .
The I installed goocanvas with Yast, imported it in python, and Openshot fired up !!
With a lot of errors in the terminal like missing Vimeoclient and lots of attributeerrors . Well, will see if it is of any influence working with it.