首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ModuleNotFoundError:没有名为“PIL”的模块

ModuleNotFoundError:没有名为“PIL”的模块
EN

Unix & Linux用户
提问于 2022-10-05 16:58:24
回答 1查看 692关注 0票数 1

我搞错了。

代码语言:javascript
运行
复制
#! /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>")

我安装了枕头。

代码语言:javascript
运行
复制
pip3 install Pillow

which pip3

/usr/local/bin/pip3

我使用python3 png2jpg.py

代码语言:javascript
运行
复制
pip3 --version
pip 22.2.2 from /usr/local/lib/python3.10/site-packages/pip (python 3.10)

我确实发现python脚本确实在UM20.04中工作。

我试了一些迈克尔·姆巴的新东西。

代码语言:javascript
运行
复制
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文件?:-)

代码语言:javascript
运行
复制
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
EN

回答 1

Unix & Linux用户

发布于 2022-10-07 01:45:49

在阅读和实验之后,这对我来说是有效的:

代码语言:javascript
运行
复制
pip uninstall PIL
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow

我还读到,将"PIL“改为"pil”对一些人来说是一种解决方案。

我希望这能帮到你。

票数 0
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/719902

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档