简体   繁体   English

没有名为“ PIL”的模块,但已满足要求

[英]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.

相关问题 没有名为“numpy”的模块,但已满足要求:numpy - No module named 'numpy' but Requirement already satisfied: numpy 需求已经满足但是ImportError:没有名为“pkg”的模块 - Requirement already satisfied but ImportError: No module named “pkg” 尽管“要求已满足”,但没有名为“bcolors”的模块 - No module named 'bcolors' although 'Requirement already satisfied' 没有名为 Selenium 的模块; 要求已经满足 - No module named Selenium; requirement already satisfied ModuleNotFoundError:没有名为“dateutil”的模块,但已满足要求 - ModuleNotFoundError: No module named 'dateutil' but Requirement already satisfied 即使已经满足要求,也没有名为selenium的模块: - No module named selenium even after Requirement already satisfied: selenium ModuleNotFoundError:即使要求已经满足,也没有名为“selenium”的模块 - ModuleNotFoundError: No module named 'selenium' even though Requirement already satisfied 使用枕头导入图像:没有名为“ PIL”的模块 - Import Image using Pillow : No module named 'PIL' Python 模块问题 - “ModuleNotFoundError”和“已满足要求” - Python module issue - “ModuleNotFoundError” and “Requirement already satisfied” 出现错误“ modulenotfounderror:没有名为“ google”的模块”,但是当尝试通过命令提示符安装时,它说要求已经满足 - getting error “modulenotfounderror: No module named 'google'” but when trying to install through command prompt it says requirement already satisfied
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM