Reputation: 3576
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:
import PIL as pillow
from PIL import Image
As someone suggested in a similar post, also, I tried
import PIL
from PIL import Image
Neither works. Both give me this error:
ImportError: No module named PIL
Also, I tried:
import Image
it gives me:
ImportError: No module named Image
Help is really appreciated!
Upvotes: 38
Views: 137470
Reputation: 552
I had a similiar issue with
ModuleNotFoundError: No module named 'PIL'
in a virtual environment created with python3 -m venv .venv
and executing a script with VS Code (which pointed to the interpreter in the virtual environment). None of the above solutions worked for me. Importing the module outside of the virtual environment worked though, without any issues.
After further delving it turned out that pip install pillow
was not installing the pillow
module to the virtual environment, because I had pillow
already installed on the main system interpreter.
The work around to this is to change the value of include-system-site-packages
to true
in the .venv/pyvenv.cfg
file. Then pillow
is imported without any issues when using the virtual environment interpreter and having pillow
installed on the main system interpreter.
Upvotes: 0
Reputation: 2834
For Windosws 11 Fixed mine by using
pip uninstall pillow
and then
pip install pillow
Upvotes: 0
Reputation: 311
This solution is for pip version 20 and using PyCharm. I'd upgrade pip to version 20.0.2 as pip suggested but I had to get back to version 19
python -m pip install pip==19.3.1
I also installed Pillow from command line
pip install Pillow
And finally installed Pillow inside PyCharm on Settings -> Project:your-project-name -> Project Interpreter, clicked on + button and installed Pillow.
Upvotes: 0
Reputation: 354
For me, when I was trying to use PIL in PyCharm, initially the Project Interpreter was not looking at the correct location for Python 3.7. This has been corrected and using PIL works for me now (corrected Interpreter shown in image attached).
Upvotes: 0
Reputation: 2135
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.
Note that I didn't use virtualenv
.
First, you need to check which python is used by the system. In the Terminal, run
which -a python
You'll get something similar to this:
nicholass-mbp:~ nicholaslie$ which -a python
/usr/local/bin/python
/usr/local/bin/python
/usr/bin/python
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.
I used Homebrew for managing my system packages such as node
, python
, etc. So what I did was reinstall python3
with Homebrew with:
brew reinstall python
, then run pip3 install pillow
.
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.
Upvotes: 2
Reputation: 28529
You can use python -m pip install Pillow
or pip install Pillow
Upvotes: 6
Reputation: 1469
In my case, on Windows, all I needed to do is to run:
pip install pillow
Upvotes: 35
Reputation: 1148
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:
pip install --upgrade pip
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:
Python 2.7.12 (default, Jun 29 2016, 13:16:51)
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL
>>> from PIL import Image
>>> Image
<module 'PIL.Image' from '/usr/local/lib/python2.7/site-packages/PIL/Image.pyc'>
Upvotes: 15