如何在Mac上从python中的PIL导入多个函数

如何在Mac上从python中的PIL导入多个函数,python,macos,python-imaging-library,Python,Macos,Python Imaging Library,我不熟悉python中的图像编辑,仍在尝试了解有关PIL的内容 我试图在python中使用PIL在图像上创建自己的过滤器,但python不允许我导入多个函数 from PIL import Image,Imagecolor,Imagefilter... 我想在计算机中使用图像,只是熟悉Python中的模块使用 当我尝试使用一个函数时,它会说其他函数未识别..比如。。如果我只导入ImageFilter import ImageFilter img = Image.open('imagespup

我不熟悉python中的图像编辑,仍在尝试了解有关PIL的内容

我试图在python中使用PIL在图像上创建自己的过滤器,但python不允许我导入多个函数

from PIL import Image,Imagecolor,Imagefilter...
我想在计算机中使用图像,只是熟悉Python中的模块使用

当我尝试使用一个函数时,它会说其他函数未识别..比如。。如果我只导入ImageFilter

import ImageFilter

img = Image.open('imagespuppy.jpg') 
out = img.filter(ImageFilter.DETAIL)

img.show()
它显示一个错误,称为未定义的“图像”


需要帮助

python中的导入和
用于包含其他模块。假设我有一个模块
math
,它有几个函数

  • sqrt(平方根)
  • 模(模数)
  • 如果我想在我的另一个文件中包含数学模块,并在没有模块名称的情况下使用它们(
    math
    ),我必须这样做

    from math import sqrt, mod
    sqrt(25)
    
    现在如果我必须用模块名访问函数

    import math
    math.sqrt(25)
    
    进入用户案例图像和图像过滤器是PIL模块的一部分。下面是如何导入它的

    from PIL import Image, ImageFilter
    
    img = Image.open('imagespuppy.jpg') 
    out = img.filter(ImageFilter.DETAIL)
    
    img.show()
    

    在您的
    from PIL
    语句中,您没有正确地将导入内容大写
    Imagecolor
    必须是
    Imagecolor
    ImageFilter
    必须是
    ImageFilter
    。这能解决您的问题吗?如果您想使用Image类,您应该将它与ImageFilter以及您可能使用的库中的任何其他内容一起导入。它成功了!!我还有一个疑问,我见过一些例子,语句是在终端上键入的,而不是任何文本编辑器。这是怎么回事。它说这在交互式shell上工作,这意味着什么?为什么不先从python开始,然后再切换到新模块。你似乎在问一些基本的问题。