Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import image in python

hello I am a beginner in python and I have problems executing my code . how can i fix this error with 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
like image 587
Nadin Martini Avatar asked Jul 13 '18 09:07

Nadin Martini


People also ask

How do I import an image into Python PIL?

To load the image, we simply import the image module from the pillow and call the Image. open(), passing the image filename. Instead of calling the Pillow module, we will call the PIL module as to make it backward compatible with an older module called Python Imaging Library (PIL).

How do I read a JPEG in Python?

Read An image We use cv2. imread() function to read an image. The image should be placed in the current working directory or else we need to provide the absoluate path.

Can Python open images?

You can read an image in Python using using Image class of PIL library. In this tutorial, we shall learn how to read or open an image using Pillow library, and different situations one might encounter, with the help of example programs.


3 Answers

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

from PIL import Image, ImageDraw

That should get you farther along.

like image 69
Mike Housky Avatar answered Oct 17 '22 16:10

Mike Housky


Try this:

from PIL import Image

or else you haven't installed it yet:

pip install pillow
like image 39
Oumab10 Avatar answered Oct 17 '22 17:10

Oumab10


I had a similar Problem, this post helped me: 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.

like image 2
Blue Avatar answered Oct 17 '22 17:10

Blue