Nameerror: Name 'Display' Is Not Defined

Nameerror: Name 'Display' Is Not Defined

I try to run python code using Linux terminal to display a png image.but it gives me same error again and again.

from PIL import Image
im=Image.open("/content/sample_1.png")

# Lets display the image

display(im)
2

2 Answers

You could try using im.show() instead of display():

from PIL import Image
im=Image.open("/content/sample_1.png")

# Lets display the image

im.show()

display is a command on the Linux shell, and you can't use in python directly.

If you just want to show the PNG image, you can use the following code:

import subprocess
im="/content/sample_1.png"
subprocess.getoutput("display %s" %im)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.