No Module named PIL
I know PIL is deprecated, so I installed Pillow instead, and for backward compatibility reason, Pillow is still using PIL as its module name. Here’s my pip freeze look like for Pillow: Pillow=3.2.0
Here’s how I use it in my code:
As someone suggested in a similar post, also, I tried
Neither works. Both give me this error:
Help is really appreciated!
7 Answers 7
In my case, on Windows, all I needed to do is to run:
pip install pillow
As per my comment since it helped you out and answered your problem:
The issue that you were seeing is that you had pip version 1.5.6, and the version of pip does dictate how packages are unzipped, which ultimately determines whether or not modules are loaded properly.
All that is needed is:
Which allows pip to upgrade itself.
Use sudo if you’re on Mac/Linux, otherwise you’ll likely need to ‘Run as Administrator’ on Windows.
And voila, you can now properly import the PIL modules:
I’m having this trouble too recently, so let me share my take on this. I’m on Mac OS X Mojave 10.14. I tried running the pip install pillow so many times blindly without finding deeper understanding as to where my python searches for its packages.
I encountered this error when I upgraded from OS X High Sierra to Mojave. My previously working Scrapy project just stopped running properly.
First, you need to check which python is used by the system. In the Terminal, run
You’ll get something similar to this:
This leads me to searching inside the /usr/local/ folder. Turns out there’s a folder to where my python is searching its packages, and that is inside /usr/local/lib/python2.7 ( python ) or /usr/local/lib/python3.7 ( python3 )
What my current pip install pillow do is installing the PIL package inside the /usr/local/lib/python2.7/site-packages directory, but not to /usr/local/lib/python3.7/site-packages
However, since my project uses Python 3, No module named PIL error simply tells you that the python3 instance you’re using cannot find the PIL library.
Just ensure that the PIL package is installed properly in /usr/local/lib/python3.7/site-packages and you should be good to go. Hope this helps someone.
ImportError: No module named PIL
I use this command in the shell to install PIL:
I’ve never had such problem, what do you think?
28 Answers 28
Attention: PIL is deprecated, and pillow is the successor.
On some installs of PIL, you must do
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).
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
At first install Pillow with
Then in python code you may call
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:
If for any reason you get an error, add sudo at the beginning of the command and after hitting enter type your password.
This worked for me on Ubuntu 16.04:
I found this on Wikibooks after searching for about half an hour.
you have to install Image and pillow with your python package.
or run command prompt (in windows), then navigate to the scripts folder
then run below command
On windows 10 I managed to get there with:
after which in python (python 3.7 in my case) this works fine.
and pip installed PIL in Lib\site-packages. When I moved PIL to Lib everything worked fine. I’m on Windows 10.
if you use anaconda:
On windows, try checking the path to the location of the PIL library. On my system, I noticed the path was
instead of PIL use Pillow it works
Install Specific Version:
Getting Dependency Error in Window 10 Use code: easy_install instead of pip install
Upgrade using easy install
On OSX System to install Module: Use code: brew install instead of pip install
On CentOS7 or Linux Fedora:
Command if Homebrew screws up your path on macOS:
For Python3 MacOs Homebrew screws
Verify module from list MacOs
For Execute on Anaconda as your python package manager
You will need to install Image and pillow with your python package. Rest assured, the command line will take care of everything for you.
I used conda-forge to install pillow version 5, and that seemed to work for me:
the normal conda install pillow did NOT work for me.
and it worked for me fine
use pil instead of PIL
The cleanest way to resolve this issue is by following below steps.
Step 1: Uninstall the PIL package.
Step 2: Install the Pillow using pip as shown below on windows operating systems. For other environments checkout the article No module named PIL
Step 3: The most crucial class in the Python Imaging Library is the Image class, and you can import this as shown below.
If successful, this function returns an Image object. You can now use instance attributes to examine the file contents:
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.
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.
python3—no module named PIL #3825
Comments
ljh0279 commented Nov 22, 2017
when i Loading and normalizing CIFAR10, said that ‘from PIL import Image
ModuleNotFoundError: No module named ‘PIL».
However, PIL only supports python2.7, how can i solve it?
The text was updated successfully, but these errors were encountered:
Gosicfly commented Nov 22, 2017
just try this:
pip3 install pillow
ljh0279 commented Nov 22, 2017
pillow is already installed. However, it does not work.
zou3519 commented Nov 22, 2017
I would recommend uninstalling Pillow, PIL (if they exist) and reinstalling pillow.
Something like:
ljh0279 commented Nov 22, 2017
ok. thank you! it works. I will post these questions to there in the future.
KingCyrus commented Nov 2, 2019
I would recommend uninstalling Pillow, PIL (if they exist) and reinstalling pillow.
Something like:
You saved my career! I have been on this for weeks. Thanks.
taulantisaku commented Nov 19, 2019
I would recommend uninstalling Pillow, PIL (if they exist) and reinstalling pillow.
Something like:
lukhuak commented Feb 23, 2020
Set path of NetBeans11.2 IDE to the interpreter anaconda in python 3.7.4
import cv2
import numpy as np
from PIL import Image
indolentdeveloper commented May 7, 2020
you might get below error in mac.
WARNING: The directory ‘/Users//Library/Caches/pip’ or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that director
uaahacker commented Nov 21, 2020
C:\Users\uaahacker>pip uninstall Pillow
Found existing installation: pillow 7.2.0
Uninstalling pillow-7.2.0:
Would remove:
c:\users\uaahacker\anaconda3\lib\site-packages\pil*
c:\users\uaahacker\anaconda3\lib\site-packages\pillow-7.2.0.dist-info*
Proceed (y/n)? y
Successfully uninstalled pillow-7.2.0
C:\Users\uaahacker>pip uninstall PIL
WARNING: Skipping PIL as it is not installed.
C:\Users\uaahacker>pip install Pillow
Collecting Pillow
Downloading Pillow-8.0.1-cp38-cp38-win_amd64.whl (2.1 MB)
|████████████████████████████████| 2.1 MB 261 kB/s
Installing collected packages: Pillow
Successfully installed Pillow-8.0.1
C:\Users\uaahacker>pip install PIL
ERROR: Could not find a version that satisfies the requirement PIL (from versions: none)
ERROR: No matching distribution found for PIL
Ali-Kamel commented Jan 10, 2021
I would recommend uninstalling Pillow, PIL (if they exist) and reinstalling pillow.
Something like:
isl-raph commented Sep 6, 2021
I would recommend uninstalling Pillow, PIL (if they exist) and reinstalling pillow.
Something like:
No module named PIL #3851
Comments
cheekysim commented May 14, 2019 •
What did you do?
i did pip install pillow and wrote from PIL import Image
but when i run it it just say no module named PIL
What did you expect to happen?
it would run fine and give no errors
What actually happened?
I got the error «no module named PIL»
What are your OS, Python and Pillow versions?
The text was updated successfully, but these errors were encountered:
radarhere commented May 14, 2019
I don’t suppose that you have two versions of Python set up, and you are installing into one and then trying to import from the other?
cheekysim commented May 14, 2019 •
it is installing for the right version,
i didnt have import PIL but i just tried and same error,
radarhere commented May 15, 2019
Since you have ‘venv’ in your path, I presume that the answer to this question involves the fact that you’re using a virtual environment. https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/ might prove useful.
cheekysim commented May 15, 2019
Here’s the thing:
Pip location : c:\users\cs-admin\appdata\local\programs\python\python36\lib\site-packages
Install location : ‘C:\Users\cs-admin\AppData\Local\Programs\Python\Python36\lib\site-packages’,
Hassani87 commented Dec 22, 2019
change PIL with pil
It works for me
walhekav commented Jan 26, 2020
change PIL with pil
It works for me
simple solution, but it was really pain. Thanks
Escartem commented Jun 18, 2020
sorry to comment on this old question but I already tried this and this was working but now when I do «import PIL» it says «no module named PIL» but when I do «import pil» it gave the same error «no module named PIL» in capital letters.
Lassie23 commented Jun 19, 2020 •
change PIL with pil
It works for me
it doesnt for me.
literally all i want to do is show an image in python.
i have been trying for hours.
someone please help me.
Edit: incase this matters, i went to the file location of where pip said it installed pillow, but couldnt find anything to do with pillow.
Edit 2: actually i found it, it was installed in C: instead of C:\Users \AppData\Local\Programs\Python
thats definitely a bad thing, right? if anyone could please help me i would be so grateful.
Edit 3: ok, now ive fixed it, but its saying «cannot import name ‘_imaging’ from ‘PIL’
that’s weird, as i told it to import «Image», not «_imaging». does anyone have a solution?
Escartem commented Jun 19, 2020
I found a solution that worked for me :
First I uninstalled the old version of pil located for me in %localappdata%\Programs\Python\Python37-32\Lib\site-packages\ and removed the pil folder
Then I updated Pillow using pip install Pillow==7.1.2 and adding the version was necessary because otherwise, it will install the latest version of Pillow that can work for every dependency
And then doing from PIL import Image worked
A4lfr32 commented Jun 25, 2020
change PIL with pil
It works for me
akackon commented Jul 11, 2020
When I exited my virtual environment it seemed to work
ahmedmaz24 commented Aug 11, 2020
danielcovaci commented Sep 4, 2020 •
oh em gi
i have the same problem and nothing seems to work 🙁
vienom commented Sep 16, 2020
For me it was a python version problem. Fixed it by using pip3 install Pillow and then starting the script with python3 script.py
hugovk commented Sep 16, 2020
For me it was a python version problem. Fixed it by using pip3 install Pillow and then starting the script with python3 script.py
PianoPianist commented Oct 15, 2020
Exactly, I tried everything on the internet, nothing seems to work
PianoPianist commented Oct 15, 2020
Thankfully, it’s now working. What I did was, I deleted pip from the location where it was saved, which in my case was:
C:\Users \AppData\Local\Microsoft\WindowsApps. Then I installed it again using this website: https://datatofish.com/upgrade-pip/
This time, I installed it in (I changed the location with the help of that website):
C:\Users \AppData\Local\Programs\Python\Python38-32\Scripts
Then I used pip install pillow and installed it in the same place, Python Scripts area given above. Uninstall it using pip uninstall pillow if it wasn’t already.
Then import PIL in Python and it’ll work!
znym commented Nov 6, 2020
Thankfully, it’s now working. What I did was, I deleted pip from the location where it was saved, which in my case was:
C:\Users\AppData\Local\Microsoft\WindowsApps. Then I installed it again using this website: https://datatofish.com/upgrade-pip/
This time, I installed it in (I changed the location with the help of that website):
C:\Users\AppData\Local\Programs\Python\Python38-32\Scripts
Then I used pip install pillow and installed it in the same place, Python Scripts area given above. Uninstall it using pip uninstall pillow if it wasn’t already.
Then import PIL in Python and it’ll work!
Could you please write down your approach step by step?
I’d like to try this suggestion but I am not sure if I can follow the directions correctly now.
PianoPianist commented Nov 7, 2020
Thankfully, it’s now working. What I did was, I deleted pip from the location where it was saved, which in my case was:
C:\Users\AppData\Local\Microsoft\WindowsApps. Then I installed it again using this website: https://datatofish.com/upgrade-pip/
This time, I installed it in (I changed the location with the help of that website):
C:\Users\AppData\Local\Programs\Python\Python38-32\Scripts
Then I used pip install pillow and installed it in the same place, Python Scripts area given above. Uninstall it using pip uninstall pillow if it wasn’t already.
Then import PIL in Python and it’ll work!
Could you please write down your approach step by step?
I’d like to try this suggestion but I am not sure if I can follow the directions correctly now.
When I installed pillow from command prompt, I just entered the command pip install pillow and not specified any location, so it installed pillow to the default location, which in my case was C:\Users\ \AppData\Local\Microsoft\WindowsApps (I’m pretty sure it’s the same in yours too).
Try importing PIL again in Python, and it should work!
ImportError: нет модуля с именем PIL
Я использую эту команду в оболочке для установки PIL:
у меня никогда не было такой проблемы, как вы думаете?
16 ответов:
на некоторых установках PIL, вы должны сделать
вместо import PIL (PIL на самом деле не всегда импортируется таким образом). Так как import Image работает для вас, это означает, что вы на самом деле установили PIL.
наличие другого имени для библиотеки и модуля Python необычно, но это то, что было выбрано для (некоторых версий) PIL.
вы можете получить дополнительную информацию о том, как использовать этот модуль из официальный учебник.
PS: на самом деле, на некоторые установка import PIL тут работа, которая добавляет путаницы. Это подтверждается пример из документации, как выяснил @JanneKarila, а также некоторые более поздние версии пакета MacPorts PIL (1.1.7).
внимание: PIL является устаревшим, и подушка является правопреемником.
на другой ноте, я могу настоятельно рекомендовать использование подушка который обратно совместим с PIL и лучше поддерживается/будет работать на более новых системах.
когда это установлено, вы можете сделать
тогда в коде python вы можете вызвать
это сработало для меня на Ubuntu 16.04:
на Wikibooks после поиска в течение примерно получаса.
иногда я получаю этот тип ошибки при запуске Unitest в python. Решение заключается в удалении и установке одного и того же пакета в виртуальной среде.
С помощью этой команды:
Если по какой-либо причине вы получаете сообщение об ошибке, добавьте sudo в начале команды и после нажатия enter введите свой пароль.
в windows попробуйте проверить путь к местоположению библиотеки PIL. В моей системе я заметил, что путь был
вместо пил использовать подушка он работает
вам нужно будет установить образ и подушку с вашим пакетом python. Будьте уверены, командная строка позаботится обо всем за вас.
python-m pip install image
вы должны установить образ и подушку с вашим пакетом python.
или запустите командную строку (в windows), затем перейдите в папку scripts
затем выполните команду ниже
на Windows, вам нужно загрузить его и установить.exe
У меня была такая же проблема при импорте PIL и дальнейшем импорте модулей ImageTk и Image. Я также попытался установить PIL непосредственно через pip. но успеха добиться не удалось. Поскольку между ними было предложено, чтобы PIL был устаревшим, таким образом, попытался установить подушку только через pip. подушка была успешно установлена, далее, пакет PIL был сделан по пути: python27/Lib/site-packages/.
теперь можно импортировать как изображение, так и ImageTk.
Я недавно установил Leap. Я попробовал openshot, и он не начался. Поэтому пришел сюда и нашел предложение начать с терминала, чтобы увидеть, есть ли какие-либо ошибки.
я использовал conda-forge для установки подушки версии 5, и это, казалось, работало для меня:
нормальная подушка установки conda не работала для меня.
вы, вероятно, не хватает заголовков python для построения pil. Если вы используете ubuntu или подобные, это будет что-то вроде



















