Python安装PIL报错:No module named 'PIL'的解决方法

在Python中,如果import了PIL,但是本机上并没有安装相应的组件,在运行py程序时会报错:ModuleNotFoundError: No module named 'PIL'。

D:\Python\PY>MYPYAPP.py
Traceback (most recent call last):
  File "D:\Python\PY>MYPYAPP.py", line 17, in <module>
    from PIL import Image
ModuleNotFoundError: No module named 'PIL'

  

出现上述问题时,我们简单的使用pip install PIL是无法解决问题的,正确的做法是使用pip install pillow:

D:\Python\PY>pip install pillow
Collecting pillow
  Downloading Pillow-9.2.0-cp38-cp38-win_amd64.whl (3.3 MB)
     ---------------------------------------- 3.3/3.3 MB 3.6 MB/s eta 0:00:00
Installing collected packages: pillow
Successfully installed pillow-9.2.0

  

posted @ 2022-09-25 11:20  吉小僧  阅读(5515)  评论(0编辑  收藏  举报