win10下python3.8的PIL库安装过程

1.找到Python的位置

我的是在
C:\Users\admin\AppData\Local\Programs\Python\Python38
AppData这个文件是个隐藏文件需要查询得先把隐藏文件显示出来
win10里面在Microsoft store 下载的Python我只找到了exe文件,所以就卸载然后重新下载过。
去官网下载的时候下载速度极其慢,可以去这下:
https://python123.io/download

2.PIL库的安装

PIL库:具有强大的图像处理能力
在上面找到的位置,打开终端,然后输入

pip install pillow

然后等待安装就好了。这里提供参考代码试验有没有装成功。

from PIL import Image, ImageDraw, ImageFont
def add_num(img):
draw = ImageDraw.Draw(img)
myfont = ImageFont.truetype('C:/windows/fonts/Arial.ttf', size=40)
fillcolor = "#ff0000"
width, height = img.size
draw.text((width-40, 0), '99', font=myfont, fill=fillcolor)
img.save('C:/Users/admin/Desktop/result.jpg','jpeg')
return 0
if __name__ == '__main__':
image = Image.open('C:/Users/admin/Desktop/image.jpg')
 add_num(image)

PS:windows下python3.8安装PIL:python3.8缺少Image库

python官网:
https://www.python.org/

python3.8运行使用了Image库的python脚本

运行.py脚本,报错:
Traceback (most recent call last):
File “CutPngToTga.py”, line 32, in
import PIL.Image
ModuleNotFoundError: No module named ‘PIL'

这是因为,安装的python还没有包含PIL模块

python安装PIL:
进入windows的cmd:

1.更新pip
(1)查看pip版本
pip --version
(2)更新pip

python -m pip install --upgrade pip

2.安装python的PIL(python图形库)

pip install Pillow

3.python应用导入PIL
python代码中导入Image库的一种方式:

import PIL.Image

总结

到此这篇关于win10下python3.8的PIL库安装的文章就介绍到这了,更多相关win10 python PIL库安装内容请搜索来客网以前的文章或继续浏览下面的相关文章希望大家以后多多支持来客网!