1

I am getting an error.

#! /usr/bin/python3
# On 10/4/22 I installed version Python 3.10.7
# png2jpg.py    
# Does not work

# Traceback (most recent call last):
  # File "/home/andy/Python/png2jpg.py", line 10, in <module>
    # from PIL import Image
# ModuleNotFoundError: No module named 'PIL'

import math 

import os
import sys
from PIL import Image

if len(sys.argv) > 1:
    if os.path.exists(sys.argv[1]):
        im = Image.open(sys.argv[1])
        target_name = sys.argv[1] + ".jpg"
        rgb_im = im.convert('RGB')
        rgb_im.save(target_name)
        print("Saved as " + target_name)
    else:
        print(sys.argv[1] + " not found")
else:
    print("Usage: convert2jpg.py <file>")

I installed Pillow.

pip3 install Pillow

which pip3

/usr/local/bin/pip3

I use python3 png2jpg.py

pip3 --version
pip 22.2.2 from /usr/local/lib/python3.10/site-packages/pip (python 3.10)

I did find out that the python script does work in UM 20.04.

I tried some new items from Michael Mba.

pip uninstall PIL
Cannot uninstall requirement PIL, not installed

python3 -m pip install --upgrade pip
Defaulting to user installation because normal site-packages is not writeable
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Requirement already satisfied: pip in /usr/local/lib/python3.10/site-packages (22.2.2)
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
WARNING: There was an error checking the latest version of pip.

https://jhooq.com/pip-install-connection-error/

I have no pip.conf file? :-)

Python allows you to set default command-line options with the help of pip.conf file.

Locate your pip.conf file based on your operating system -

2. Unix - $HOME/.config/pip/pip.conf
fixit7
  • 133
  • 1
  • 7
  • Can you update your question to include the output of `which pip3`? Also, how are you running your code (by running `./myscript.py` or `python myscript.py` or `python3 myscript.py` or something else)? – larsks Oct 05 '22 at 17:36
  • @larsks I edited my post with the requested info. – fixit7 Oct 05 '22 at 18:32
  • It looks like you may have two versions of Python installed. If you run `/usr/local/bin/python3`, are you able to `import PIL`? – larsks Oct 05 '22 at 18:34
  • runing /usr/local/bin/python3 gives the same message. Python 2.7.17 was installed with my Ubuntu Mate installation. I thought about removing it but read somewhere that to do so would cause a lot of problems. @larsks – fixit7 Oct 05 '22 at 18:53
  • Right, you **do not** want to remove the system Python! But that shouldn't be an issue in any case because you're explicitly running `python3`. What does `pip3 --version` output? – larsks Oct 05 '22 at 18:56
  • pip3 --version pip 22.2.2 from /usr/local/lib/python3.10/site-packages/pip (python 3.10) @larsks – fixit7 Oct 05 '22 at 19:36
  • Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/139654/discussion-between-fixit7-and-larsks). – fixit7 Oct 06 '22 at 02:33
  • Cross-posted: https://askubuntu.com/questions/1434187/modulenotfounderror-no-module-named-pil – muru Oct 07 '22 at 03:19

1 Answers1

0

After some reading and experimenting, this worked for me:

pip uninstall PIL
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow

I also read that changing "PIL" to "pil" worked as a solution for some.

I hope this helps.

  • I tried your suggestions and added the results to my post. – fixit7 Oct 07 '22 at 02:31
  • Hey @fixit7 looked at the error message from your pip upgrade attempt. I do not know the state of your network so rather than suggest multiple things here's a link that may help. https://jhooq.com/pip-install-connection-error/ [link](https://jhooq.com/pip-install-connection-error/) – Michael Mba Oct 07 '22 at 03:02