6

I'm using Python 2.7, and I am looking through one of the tuts+ tutorials

I am unable to import one of the modules in their first code segment, the ImageGrab module. I reinstalled Python Imaging Library, and checked to make sure the folder was in the site-packages. On the tuts+ site, there is a link to fixing filepaths but it is broken, and I tried looking on that site and on google for fixing the module path, but nothing worked. How can I get Python to discover the PIL module?

Thanks for any help

EDIT: So, found the problem (not really a problem, more of a cygwin doesn't want to play nice thing). If I opened the python file in the IDLE and ran the program from there using the run module command, it worked just fine. It was just command line python stuff that didn't work. Even after trying a variety of fixes, it would keep yelling about not having this file or that module (like _imaging, or Image, or anything else).

user1938805
  • 81
  • 1
  • 1
  • 4

5 Answers5

9

Have you tried:

from PIL import ImageGrab

worked for me...

Shujal
  • 252
  • 2
  • 6
4

have you tried with import Image instead of from PIL import Image? sometimes this solves the issue.

from PIL import Image
D4NI3LS
  • 305
  • 3
  • 9
  • Thanks for the response, I've tried that but sadly it did not work. Do you have any other suggestions? – user1938805 Sep 09 '13 at 00:59
  • Before asking, look for some related questions. http://stackoverflow.com/questions/15859251/why-do-i-get-importerror-no-module-named-pil?rq=1 http://stackoverflow.com/questions/10811231/python-pil-image-module-importerror-no-module-named-pil-no-module-named-image?rq=1 – D4NI3LS Sep 09 '13 at 01:02
1
# Importing Image and ImageGrab module from PIL package 
from PIL import Image, ImageGrab 
    
# creating an image object 
im1 = Image.open(r"C:\Users\sadow984\Desktop\download2.JPG") 
    
# using the grab method 
im2 = ImageGrab.grab(bbox = None) 
    
im2.show() 
sɐunıɔןɐqɐp
  • 3,332
  • 15
  • 36
  • 40
  • 1
    From Review:  Hi, please don't answer just with source code. Try to provide a nice description about how your solution works. See: [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer). Thanks – sɐunıɔןɐqɐp Aug 04 '20 at 10:59
0

The pyscreenshot module can be used to copy the contents of the screen to a PIL image memory or file. Replacement for the ImageGrab Module, which works on Windows only.

Links: home: https://github.com/ponty/pyscreenshot documentation: http://ponty.github.com/pyscreenshot

Go through this link:

https://pypi.python.org/pypi/pyscreenshot

Anand Rajagopal
  • 1,593
  • 6
  • 24
  • 40
0

Try typing this in your commandline

C:\Users"your pc username"\PycharmProjects"your project name"\venv\Scripts\python.exe -m pip install --upgrade pip

for me this worked

Stijn
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 23 '22 at 20:27