Python Forum
ImportError: No module named PIL
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ImportError: No module named PIL
#1
Hi guys,

I'm having a little trouble with the Pillow function using MacOS Monterrey 12.1. Trying to use the Pillow library (specifically Image) but getting the error:

ImportError: No module named PIL

I installed Python 3.10.2 and installed Pillow using Homebrew...but I feel like I didn't do it correctly and have had a tough time uninstalling/reinstalling and think I've kind of messed it up.

Would appreciate some help on what steps to take here; thank you in advance!
Reply
#2
Look at The right and wrong way to set Python 3 as default on a Mac
(Mar-02-2022, 02:02 PM)rudeoil18 Wrote: I installed Python 3.10.2 and installed Pillow using Homebrew...but I feel like I didn't do it correctly and have had a tough time uninstalling/reinstalling and think I've kind of messed it up.
You most test the python and pip work correctly from command line.
Also there can be be a difference with with python, python3 and pip, pip3.
Here a quick run on Windows the command is same on Mac.
So the which python and pip --version most point to same version.
Then will pip install something install to this version and if just type python(start interactive interpreter) can test that install did work
G:\div_code
λ python --version
Python 3.10.0

G:\div_code
λ which python
/c/python310/python

G:\div_code
λ pip --version
pip 21.3.1 from C:\python310\lib\site-packages\pip (python 3.10)

G:\div_code
λ pip install pillow --upgrade
Requirement already satisfied: pillow in c:\python310\lib\site-packages (9.0.1)

G:\div_code
λ python
Python 3.10.0 (tags/v3.10.0:b494f59, Oct  4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image
>>>
>>> im = Image.open('task.jpg')
>>> im.show()
Can also use py
G:\div_code
λ py --list
Installed Pythons found by py Launcher for Windows
 -3.10-64 *
 -3.9-64
 -3.7-32
 -3.6-32
 -3.4-32
 -2.7-32
* show the lasted version found.
So py will always use the lasted version found,even if OS path is messed up.
G:\div_code
λ py --version
Python 3.10.0

G:\div_code
λ py -m pip --version
pip 21.3.1 from C:\Python310\lib\site-packages\pip (python 3.10
Reply
#3
(Mar-02-2022, 02:28 PM)snippsat Wrote: Look at The right and wrong way to set Python 3 as default on a Mac
(Mar-02-2022, 02:02 PM)rudeoil18 Wrote: I installed Python 3.10.2 and installed Pillow using Homebrew...but I feel like I didn't do it correctly and have had a tough time uninstalling/reinstalling and think I've kind of messed it up.
You most test the python and pip work correctly from command line.
Also there can be be a difference with with python, python3 and pip, pip3.
Here a quick run on Windows the command is same on Mac.
So the which python and pip --version most point to same version.
Then will pip install something install to this version and if just type python(start interactive interpreter) can test that install did work
G:\div_code
λ python --version
Python 3.10.0

G:\div_code
λ which python
/c/python310/python

G:\div_code
λ pip --version
pip 21.3.1 from C:\python310\lib\site-packages\pip (python 3.10)

G:\div_code
λ pip install pillow --upgrade
Requirement already satisfied: pillow in c:\python310\lib\site-packages (9.0.1)

G:\div_code
λ python
Python 3.10.0 (tags/v3.10.0:b494f59, Oct  4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image
>>>
>>> im = Image.open('task.jpg')
>>> im.show()
Can also use py
G:\div_code
λ py --list
Installed Pythons found by py Launcher for Windows
 -3.10-64 *
 -3.9-64
 -3.7-32
 -3.6-32
 -3.4-32
 -2.7-32
* show the lasted version found.
So py will always use the lasted version found,even if OS path is messed up.
G:\div_code
λ py --version
Python 3.10.0

G:\div_code
λ py -m pip --version
pip 21.3.1 from C:\Python310\lib\site-packages\pip (python 3.10

So these are the returns that I get:

user@user-MacBook-Pro-16 ~ % pip3 --version
pip 22.0.3 from /opt/homebrew/lib/python3.9/site-packages/pip (python 3.9)
user@user-MacBook-Pro-16 ~ % python3 --version
Python 3.9.10
user@user-MacBook-Pro-16 ~ % python --version
Python 2.7.18
user@user-MacBook-Pro-16 ~ % pip --version
zsh: command not found: pip

I installed Pillow using homebrew (brew install Pillow) and it seems the installation occurred correctly.

However, I am still getting the error from Pycharm:

/usr/bin/python2.7 "/Users/user/Library/Mobile Documents/com~apple~CloudDocs/NFTs/Wasted/render.py"
Traceback (most recent call last):
File "/Users/user/Library/Mobile Documents/com~apple~CloudDocs/NFTs/Wasted/render.py", line 1, in <module>
from PIL import Image
ImportError: No module named PIL
Reply
#4
(Mar-02-2022, 02:43 PM)rudeoil18 Wrote: However, I am still getting the error from Pycharm:
You are using a Python 2.7 in PyChram,look at Configure a Python interpreter and choice the right version.
Now is Python 3.9.10 your default Python 3 version.
Quote:I installed Python 3.10.2
Also don't show up in your command line.
So search for brew alias python mac to set this version as default,or look at link that postet that talk about this.
Also if you test py --version do it point to your Python 3.10.2.
Reply
#5
(Mar-02-2022, 02:58 PM)snippsat Wrote:
(Mar-02-2022, 02:43 PM)rudeoil18 Wrote: However, I am still getting the error from Pycharm:
You are using a Python 2.7 in PyChram,look at Configure a Python interpreter and choice the right version.
Now is Python 3.9.10 your default Python 3 version.
Quote:I installed Python 3.10.2
Also don't show up in your command line.
So search for brew alias python mac to set this version as default,or look at link that postet that talk about this.
Also if you test py --version do it point to your Python 3.10.2.

So I have updated the interpreter in PyCharm to 3.10.2 (but still get the same error).

When I test python --version I get 2.7.18...so I guess I need to change my system setting to 3.10.2? I did do that using pyenv and the instructions you sent to me in the original link..when I test pyenv version it does say 3.10.2.
Reply
#6
(Mar-02-2022, 03:18 PM)rudeoil18 Wrote:
Quote:
Also don't show up in your command line.
You most alias to both python and pip to the new version .
Look at this link .
So when you do pip --version or pip3 --version it most point to Python 3.10.2.
Then will pip3 install pillow install to Python 3.10.2 and when you choice Python 3.10.2 in PyCharm it will work.

Now it do pip3 install pillow it will install to Python 3.9.10,then if choice this version it PyCharm it will work.
But to use your new version need to look at alias or pyenv( that the first advice in link i posted)
My tutorial.
Reply
#7
(Mar-02-2022, 07:10 PM)snippsat Wrote:
(Mar-02-2022, 03:18 PM)rudeoil18 Wrote: Also don't show up in your command line.
You most alias to both python and pip to the new version .
Look at this link .
So when you do pip --version or pip3 --version it most point to Python 3.10.2.
Then will pip3 install pillow install to Python 3.10.2 and when you choice Python 3.10.2 in PyCharm it will work.

Now it do pip3 install pillow it will install to Python 3.9.10,then if choice this version it PyCharm it will work.
But to use your new version need to look at alias or pyenv( that the first advice in link i posted)
My tutorial.

OK I think I understand the issue; Pillow is installed on Python 3.9.10 but I have 3.10.2 selected in PyCharm.

I tried to use your alias article to link to Python 3.10.2 but it doesn't work, when I type pip3 --version it is still linked to Python 3.9.10

How can I find the filepath for Python 3.9.10 so I can change to that interpreter in PyCharm?
Reply
#8
(Mar-02-2022, 08:01 PM)rudeoil18 Wrote: How can I find the filepath for Python 3.9.10 so I can change to that interpreter in PyCharm?
You already gotten it.
(Mar-02-2022, 02:43 PM)rudeoil18 Wrote: user@user-MacBook-Pro-16 ~ % pip3 --version
pip 22.0.3 from /opt/homebrew/lib/python3.9/site-packages/pip (python 3.9)
So path to Python 3.9.10 is /opt/homebrew/lib/python3.9

py as mention will always use latest version.
Then should which py or py -m pip --version give path to Python 3.10.2.
If test as i did you will see bye the * which version py use,which should always by lasted installed.
G:\div_code
λ py --list
Installed Pythons found by py Launcher for Windows
 -3.10-64 *
 -3.9-64
 -3.7-32
 -3.6-32
 -3.4-32
 -2.7-32
Reply
#9
(Mar-02-2022, 11:03 PM)snippsat Wrote:
(Mar-02-2022, 08:01 PM)rudeoil18 Wrote: How can I find the filepath for Python 3.9.10 so I can change to that interpreter in PyCharm?
You already gotten it.
(Mar-02-2022, 02:43 PM)rudeoil18 Wrote: user@user-MacBook-Pro-16 ~ % pip3 --version
pip 22.0.3 from /opt/homebrew/lib/python3.9/site-packages/pip (python 3.9)
So path to Python 3.9.10 is /opt/homebrew/lib/python3.9

py as mention will always use latest version.
Then should which py or py -m pip --version give path to Python 3.10.2.
If test as i did you will see bye the * which version py use,which should always by lasted installed.
G:\div_code
λ py --list
Installed Pythons found by py Launcher for Windows
 -3.10-64 *
 -3.9-64
 -3.7-32
 -3.6-32
 -3.4-32
 -2.7-32

Thanks...we're so close to fixing this..any reason why I can't seem to select the 3.9 HomeBrew folder (in screenshot below)?

Attached Files

Thumbnail(s)
   
Reply
#10
(Mar-03-2022, 12:34 PM)rudeoil18 Wrote: Thanks...we're so close to fixing this..any reason why I can't seem to select the 3.9 HomeBrew folder (in screenshot below)?
You most scroll down to python and select it.
Slow down and try to read what the doc say.
PyCharm Wrote:When you configure a Python interpreter, you need to specify the path to the Python executable in your system.
Also the Python executable is python.


All info you need is in this Thread,and learn to do stuff from command line indecently of any editors.
Look at post #2 there do i test python version and install pillow and test that i work all from command line.
So then can choose python 3.10 interpreter in VS Code(editor that i use) or same in PyCharm.
Then will pillow work in editor in the same as my test from command line.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  no module named 'docx' when importing docx MaartenRo 1 895 Dec-31-2023, 11:21 AM
Last Post: deanhystad
  Problem with pymodbus - ModuleNotFoundError: No module named 'pymodbus.client.sync' stsxbel 2 23,824 Nov-02-2023, 08:20 AM
Last Post: South_east
  ModuleNotFoundError: No module named 'requests' Serg 18 2,605 Oct-29-2023, 11:33 PM
Last Post: Serg
  Resolving ImportError: No module named gdb (Python in C++) mandaxyz 3 1,465 Oct-04-2023, 02:43 PM
Last Post: mandaxyz
  ModuleNotFoundError: No module named 'PyPDF2' Benitta2525 1 1,527 Aug-07-2023, 05:32 AM
Last Post: DPaul
  ModuleNotFoundError: No module named 'eyed3' Wimpy_Wellington 2 1,350 Jul-10-2023, 03:37 AM
Last Post: Wimpy_Wellington
  How to fix this error: ModuleNotFoundError: No module named 'notears' yaoyao22 2 1,050 Jul-09-2023, 11:24 AM
Last Post: yaoyao22
  Help with pyinstaller "No module named" korenron 9 9,146 Jun-15-2023, 12:20 PM
Last Post: snippsat
  Problem with Pyinstaller. No module named '_tkinter' tonynapoli2309 0 1,021 May-15-2023, 02:38 PM
Last Post: tonynapoli2309
  ModuleNotFoundError: No module named 'omsdk.sdkproto' donvito7 4 1,873 Oct-20-2022, 02:56 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020