已经安装pillow还是提示No module named 'PIL'

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了已经安装pillow还是提示No module named 'PIL'相关的知识,希望对你有一定的参考价值。

#-*- coding:utf-8 -*-
#from PIL.Image import core as image
from PIL import Image
import argparse

#\u547d\u4ee4\u884c\u8f93\u5165\u53c2\u6570\u5904\u7406
parser = argparse.ArgumentParser()

parser.add_argument('file') #\u8f93\u5165\u6587\u4ef6
parser.add_argument('-o', '--output') #\u8f93\u51fa\u6587\u4ef6
parser.add_argument('--width', type = int, default = 80) #\u8f93\u51fa\u5b57\u7b26\u753b\u5bbd
parser.add_argument('--height', type = int, default = 80) #\u8f93\u51fa\u5b57\u7b26\u753b\u9ad8

#\u83b7\u53d6\u53c2\u6570
args = parser.parse_args()

IMG = args.file
WIDTH = args.width
HEIGHT = args.height
OUTPUT = args.output

ascii_char = list("$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1[]?-_+~<>i!lI;:,\"^`'. ")

# \u5c06256\u7070\u5ea6\u6620\u5c04\u523070\u4e2a\u5b57\u7b26\u4e0a
def get_char(r,g,b,alpha = 256):
if alpha == 0:
return ' '
length = len(ascii_char)
gray = int(0.2126 * r + 0.7152 * g + 0.0722 * b)

unit = (256.0 + 1)/length
return ascii_char[int(gray/unit)]

if __name__ == '__main__':

im = Image.open(IMG)
im = im.resize((WIDTH,HEIGHT), Image.NEAREST)

txt = ""

for i in range(HEIGHT):
for j in range(WIDTH):
txt += get_char(*im.getpixel((j,i)))
txt += '\n'

print (txt)

#\u5b57\u7b26\u753b\u8f93\u51fa\u5230\u6587\u4ef6
if OUTPUT:
with open(OUTPUT,'w') as f:
f.write(txt)
else:
with open("output.txt",'w') as f:
f.write(txt)

参考技术A 用pip list 看下是否安装成功追问

Django (1.10.6)
image (1.5.5)
nose (1.3.7)
Pillow (3.4.2)
pip (9.0.1)
setuptools (32.1.0)
wheel (0.29.0)

追答

我的可以,pillow版本4.0.0 ,python3.5 没有报错,自己在检查下吧

安装suds,提示No module named 'client'

最近在研究webservice,但是在线安装suds的时候提示No module named ‘client‘

技术图片

 

 提示没有client模块,提示这个错误主要还是因为没有安装client模块

在线安装client模块就好了

技术图片

 

以上是关于已经安装pillow还是提示No module named 'PIL'的主要内容,如果未能解决你的问题,请参考以下文章

Django遇到问题:pip安装了django,但是还是提示ModuleNotFoundError: No module named 'django'

安装suds,提示No module named 'client'

pip升级导致错误 多个pip导致明明已经安装了包但是报no module错误

Python 调用 xlrd和 xlwt,已经通过 pip 安装过了,但是在运行中提示:no module named xlwt/xlrd

python中安装了pil库,但是编译的时候还是提示No module named 'PIL'

cannot import name '_imaging' 与No module named PIL解决方法