按照惯例先吟诗一首

听筝
唐代:李端
鸣筝金粟柱,素手玉房前。
欲得周郎顾,时时误拂弦。

由于需要使用Python操作图片,想使用sudo pip install PIL引入PIL(Python Imaging Library)库,但是结果如下:

1
2
could not find a version that satisfies the requirement PIL.(form versions:)
No matching distribution found for PIL.

这个提示很费解,只能去找度娘了,原来已经用Pillow代替了PIL,在使用方面没有不同,API都是相同的。真是个挨千刀的,提示信息里怎么不告诉我们这些刚学Python的小白呢,还得白忙活半天。既然这样那就老老实实安装Pillow吧。但是又发现Pillow需要依赖multiprocessing,所以必须先安装multiprocessing。命令如下:

1
sudo pip install multiprocessing

接着再执行如下命令:

sudo pip install Pillow

引入模块要按照下面的方式写(注意大小写)
第一种:from PIL import Image
第二种:from PIL.Image(用这种方式时,下面使用时也得写成PIL.Image.open(‘1.png’),或者可以在引入时修改下模块名,如from PIL.Image as image)

引入之后就可以正常使用了。