[英]No module named 'PIL' but requirement Pillow already satisfied
I'm trying use Image from PIL but when i run my script file it says, 我正在尝试使用PIL中的图片,但是当我运行脚本文件时却说,
Traceback (most recent call last): File "script.py", line 12, in from PIL import Image ModuleNotFoundError: No module named 'PIL'
追溯(最近一次调用):文件“ script.py”,行12,来自PIL导入Image ModuleNotFoundError:没有名为“ PIL”的模块
But i can see that Pillow 5.0.0 is install when i list all modules using pip list. 但是当我使用pip list列出所有模块时,我可以看到安装了Pillow 5.0.0。
i have already searched for solutions but most of them point out to install Pillow, which i already have! 我已经在寻找解决方案,但大多数都指出要安装我已经拥有的Pillow! what am i doing wrong?
我究竟做错了什么?
I have a script file to download images from internet it uses Pillow, i have tried all known solutions but they all point to install pillow again and again. 我有一个脚本文件可以从Internet使用Pillow下载图像,我尝试了所有已知的解决方案,但它们都指向一次又一次安装枕头。
import sys, os, multiprocessing, urllib, csv
from io import StringIO
from PIL import Image
def ParseData(data_file):
csvfile = open(data_file, 'r')
csvreader = csv.reader(csvfile)
key_url_list = [line[:2] for line in csvreader]
return key_url_list[1:] # Chop off header
def DownloadImage(key_url):
out_dir = sys.argv[2]
(key, url) = key_url
filename = os.path.join(out_dir, '%s.jpg' % key)
if os.path.exists(filename):
print('Image %s already exists. Skipping download.' % filename)
return
try:
response = urllib2.urlopen(url)
image_data = response.read()
except:
print('Warning: Could not download image %s from %s' % (key, url))
return
try:
pil_image = Image.open(StringIO(image_data))
except:
print('Warning: Failed to parse image %s' % key)
return
try:
pil_image_rgb = pil_image.convert('RGB')
except:
print('Warning: Failed to convert image %s to RGB' % key)
return
try:
pil_image_rgb.save(filename, format='JPEG', quality=90)
except:
print('Warning: Failed to save image %s' % filename)
return
def Run():
if len(sys.argv) != 3:
print('Syntax: %s <data_file.csv> <output_dir/>' % sys.argv[0])
sys.exit(0)
(data_file, out_dir) = sys.argv[1:]
if not os.path.exists(out_dir):
os.mkdir(out_dir)
key_url_list = ParseData(data_file)
pool = multiprocessing.Pool(processes=50)
pool.map(DownloadImage, key_url_list)
if __name__ == '__main__':
Run()
Asked my friend for help on this matter as he's a python dev! 向我的朋友寻求帮助,因为他是python开发人员! So he said anaconda latest on windows is unstable and recommended to use anaconda on Linux.
因此,他说Windows上最新的anaconda不稳定,建议在Linux上使用anaconda。 So i tried in Fedora workstation and then i didn't face any problem.
所以我在Fedora工作站上尝试过,然后我没有遇到任何问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.