How to open an image in Python 3.7?

IntelliJ_Please picture IntelliJ_Please · Sep 3, 2018 · Viewed 14.2k times · Source

How do I open an Image in Python 3.7? I tried:

1.Import Image Image.open("File_name.jpg")

Error received: ImportError: No module named 'Image'

  1. Import cv2 image = cv2.imread('backround.jpg')

Error received: ImportError: No module named 'cv2'

Please let me know of any other ways.

Answer

Mohamed Ali Mimouni picture Mohamed Ali Mimouni · Sep 3, 2018

there are many libraries made for theses cases

so i'll explain pillow

first you need to install it you can use pip : pip install Pillow

or easy install : easy_install Pillow

from PIL import Image
im = Image.open(".../path_of_the_image/name.jpg")
im.show()

for more details you can visit the official documentation here