在python中导入图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51321960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 19:49:20  来源:igfitidea点击:

Import image in python

pythonpython-importimporterror

提问by Nadine Martini

hello I am a beginner in python and I have problems executing my code . how can i fix this error with python:

你好,我是 python 的初学者,我在执行我的代码时遇到了问题。我如何用 python 修复这个错误:

import cgitb
cgitb.enable()

print('Content-type: text/html\r\n')
print('\r\n')

import Image, ImageDraw

import sys
import math, random
from itertools import product
from ufarray import *

    ModuleNotFoundError: No module named 'Image'
          args = ("No module named 'Image'",)
          msg = "No module named 'Image'"
          name = 'Image'
          path = None
          with_traceback = <built-in method with_traceback of ModuleNotFoundError

回答by Mike Housky

Make sure you have installed Pillow(the supported, open-source version of the PIL Python Image Library) and then change your import to:

确保您已安装Pillow(受支持的 PIL Python 图像库的开源版本),然后将导入更改为:

from PIL import Image, ImageDraw

That should get you farther along.

那应该会让你走得更远。

回答by Blue

I had a similar Problem, this post helped me: How to insert an image in python

我有一个类似的问题,这篇文章帮助了我:How to insert an image in python

What they basically use is:

他们主要使用的是:

import Image
myImage = Image.open("your_image_here");
myImage.show();

For more help I would need your full code. Even after the edit it is not quite clear to me what is your code, what is the error and what you are actually trying to do.

如需更多帮助,我需要您的完整代码。即使在编辑之后,我也不太清楚您的代码是什么,错误是什么以及您实际尝试做什么。

回答by Oumab10

Try this:

尝试这个:

from PIL import Image

or else you haven't installed it yet:

或者你还没有安装它:

pip install pillow