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!
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:
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'>
You can use python -m pip install Pillow
or pip install Pillow
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With