ModuleNotFoundError: 'PIL'이라는 모듈이 없습니다.

ModuleNotFoundError: 'PIL'이라는 모듈이 없습니다.

오류가 발생합니다.

#! /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>")

베개를 설치했어요.

pip3 install Pillow

which pip3

/usr/local/bin/pip3

저는 python3 png2jpg.py를 사용합니다.

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

Python 스크립트가 UM 20.04에서 작동한다는 것을 알았습니다.

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/

pip.conf 파일이 없나요? :-)

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

답변1

몇 가지를 읽고 실험한 후에 이것이 나에게 도움이 되었습니다.

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

또한 "PIL"을 "pil"로 변경하는 것이 어떤 사람들에게는 해결책이라는 내용도 읽었습니다.

이게 도움이 되길 바란다.

관련 정보