如何在Python中显示jpg文件?

hku*_*s10 22 python

def show():

    file = raw_input("What is the name of the image file? ")

    picture = Image(file)

    width, height = picture.size()

    pix = picture.getPixels()
Run Code Online (Sandbox Code Playgroud)

我正在尝试编写代码来显示此图像,但此代码不提供图像.如何更改我的代码才能显示此图像?

tia*_*ldt 44

import Image

image = Image.open('File.jpg')
image.show()
Run Code Online (Sandbox Code Playgroud)

  • 这个答案要求您安装[Pillow](https://pillow.readthedocs.io/en/3.1.x/installation.html#basic-installation)(或原始[PIL](https://bitbucket.org/) effbot/pil-2009-raclette))首先.注意Pillow的语法需要`来自PIL import Image`. (12认同)
  • 这只是启动外部查看器应用程序 (2认同)

eLo*_*ato 19

别忘了包括

import Image
Run Code Online (Sandbox Code Playgroud)

为了显示它使用这个:

Image.open('pathToFile').show()
Run Code Online (Sandbox Code Playgroud)