PIL's __init__.py is just an empty stub as is common. It won't magically import anything by itself.

When you do from PIL import Image it looks in the PIL package and finds the file Image.py and imports that. When you do PIL.Image you are actually doing an attribute lookup on the PIL module (which is just an empty stub unless you explicitly import stuff).

In fact, importing a module usually doesn't import submodules. os.path is a famous exception, since the os module is magic.

More info:
The Image Module

Answer from Antimony on Stack Overflow
🌐
GitHub
github.com › python-pillow › Pillow › issues › 6464
AttributeError: module 'PIL' has no attribute 'features' · Issue #6464 · python-pillow/Pillow
July 26, 2022 - AttributeError: module 'PIL' has no attribute 'features'#6464 · Copy link · Lvjinhong · opened · on Jul 26, 2022 · Issue body actions · Trying to intercept the screen · Bug happened · win10, python 3.10 , Pillow 9.2 · from PIL import Image,ImageGrab PIL.features.get_supported_features() def pill(pa): x1=pa[0] x2=pa[1] y1=pa[2] y2=pa[3] img=ImageGrab.grab(x1,y1,x2,y2) img.show() pill([0,880,200,1000]) No one assigned ·
Author   Lvjinhong
Discussions

I am getting AttributeError: module 'PIL' has no attribute 'Image' - Beginner (2018) - fast.ai Course Forums
While on lesson 1 on code line - plot_val_with_title(rand_by_correct(True), “Correctly classified”) i am getting the error - module ‘PIL’ has no attribute ‘Image’. I cant move forward with it , can someone please help me out? TIA More on forums.fast.ai
🌐 forums.fast.ai
0
April 23, 2018
PIL has no attribute: Image
Did you actually install the package Pillow? As when you installed 'PIL' chances are you've downloaded some ancient library. See installation instructions https://pillow.readthedocs.io/en/stable/installation.html More on reddit.com
🌐 r/learnpython
5
3
September 30, 2021
AttributeError: module 'PIL.Image' has no attribute 'mage'
What did you do? Tried to make an image converter, from PNG to JPEG/JPG What did you expect to happen? That it converted the image What actually happened? The error is the following Traceback (most recent call last): File "C:/Users/xxx/.... More on github.com
🌐 github.com
3
February 18, 2019
why not from PIL import Image
I wonder why not from PIL import Image in https://github.com/bethgelab/foolbox/blob/master/foolbox/utils.py#L76-L78 In major open sources, they use from PIL import Image such as pillow official doc... More on github.com
🌐 github.com
5
February 12, 2018
🌐
GitHub
github.com › python-pillow › Pillow › issues › 6614
Make `import PIL; PIL.Image` work · Issue #6614 · python-pillow/Pillow
September 23, 2022 - With Pillow 9.2.0 and (e.g.) matplotlib 3.5.2: $ python3 -c 'import PIL; PIL.Image' Traceback (most recent call last): File " ", line 1, in AttributeError: module 'PIL' has no attribute 'Image' $ python3 -c 'import matplo...
Author   Kodiologist
🌐
Fast.ai
forums.fast.ai › part 1 (2018) › beginner (2018)
I am getting AttributeError: module 'PIL' has no attribute 'Image' - Beginner (2018) - fast.ai Course Forums
April 23, 2018 - While on lesson 1 on code line - plot_val_with_title(rand_by_correct(True), “Correctly classified”) i am getting the error - module ‘PIL’ has no attribute ‘Image’. I cant move forward with it , can someone please help me…
🌐
Reddit
reddit.com › r/learnpython › pil has no attribute: image
r/learnpython on Reddit: PIL has no attribute: Image
September 30, 2021 -

Hey, everyone!
I'm trying to execute this notebook, but I came across an attribute error: PIL has no attribute Image.

I tried implementing "from PIL import Image" , and other common fixes available on StackOverflow, but I didn't get anywhere. I want to be able to plot the images. And not using matplotlib. Is there any workaround to this?

🌐
Sololearn
sololearn.com › en › Discuss › 1834329 › imagegrab-not-working
ImageGrab not working, | Sololearn: Learn to code for FREE!
June 10, 2019 - Heres the Error Code I keep getting when I run it: Traceback (most recent call last): File "C:\Users\steph\Desktop\Screen\quickGrab.py", line 11, in <module> screenGrab() File "C:\Users\steph\Desktop\Screen\quickGrab.py", line 6, in screenGrab im = ImageGrab.Grab() AttributeError: module 'PIL.ImageGrab' has no attribute 'Grab' Here's the code I'm using: from PIL import ImageGrab import os import time def screenGrab(): im = ImageGrab.Grab() im.save(os.getcwd() + "\\full_snap_" + str( int(time.time())) + ".png", "PNG") if __name__ == '__main__' : screenGrab()
🌐
GitHub
github.com › python-pillow › Pillow › issues › 3662
AttributeError: module 'PIL.Image' has no attribute 'mage' · Issue #3662 · python-pillow/Pillow
February 18, 2019 - The error is the following Traceback (most recent call last): File "C:/Users/xxx/.PyCharmEdu2018.3/config/scratches/ImageConvertion.py", line 4, in im = Image.mage.open ("2.png") AttributeError: module 'PIL.Image' has no attribute 'mage
Author   oppne
Find elsewhere
🌐
GitHub
github.com › bethgelab › foolbox › issues › 101
why not from PIL import Image · Issue #101 · bethgelab/foolbox
February 12, 2018 - I wonder why not from PIL import Image in https://github.com/bethgelab/foolbox/blob/master/foolbox/utils.py#L76-L78 In major open sources, they use from PIL import Image such as pillow official documents and pytorch/torchvision. In addit...
Author   crcrpar
🌐
GitHub
github.com › OpenTTD › nml › issues › 39
(AttributeError) "module 'PIL.Image' has no attribute 'VERSION'". · Issue #39 · OpenTTD/nml
June 3, 2019 - I am working on a Windows 64 bit laptop with Conda v2019.03, running a Python 3.6.0 environment. After installing all the dependencies, when I try to run nmlc -h it shows me the following error: nmlc ERROR: nmlc: An internal error has occurred: nmlc-version: 0.4.5 Error: (AttributeError) "module 'PIL.Image' has no attribute 'VERSION'".
Author   oss-vineet
Top answer
1 of 2
2

This is a known versioning issue between cinnamon and pillow >= 6.0.0. You can find more info here. As a previous commenter said, you can find the error in /usr/share/cinnamon/cinnamon-settings/bin/imtools.py. However, changing Image.VERSION to PIL.VERSION will not fix the issue for pillow >= 7.0.0. You must instead change the line to if Image.__version__ == '1.1.7':.

2 of 2
1

If you are comfortable with python. You can modify /usr/share/cinnamon/cinnamon-settings/bin/imtools.py.

  1. Make a backup of the file. i.e
sudo cp /usr/share/cinnamon/cinnamon-settings/bin/imtools.py /usr/share/cinnamon/cinnamon-settings/bin/imtools.py.bk
  1. Open /usr/share/cinnamon/cinnamon-settings/bin/imtools.py with nano
sudo nano /usr/share/cinnamon/cinnamon-settings/bin/imtools.py
  1. Delete line 623 to 636. And shift lines 637 to 645 4 spaces to the left.

Before:

if Image.VERSION == '1.1.7':

    def split(image):
        """Work around for bug in Pil 1.1.7

        :param image: input image
        :type image: PIL image object
        :returns: the different color bands of the image (eg R, G, B)
        :rtype: tuple
        """
        image.load()
        return image.split()
else:

    def split(image):
        """Work around for bug in Pil 1.1.7

        :param image: input image
        :type image: PIL image object
        :returns: the different color bands of the image (eg R, G, B)
        :rtype: tuple
        """
        return image.split()

After:

def split(image):
    """Work around for bug in Pil 1.1.7

    :param image: input image
    :type image: PIL image object
    :returns: the different color bands of the image (eg R, G, B)
    :rtype: tuple
    """
    return image.split()

A check for version Image.VERSION 1.1.7 is not needed if you are using current version of PIL.

🌐
Reddit
reddit.com › r/learnpython › can't load imagegrab from pil
r/learnpython on Reddit: Can't load ImageGrab from PIL
March 22, 2020 -

I'm really confused here. I have a_file.py which contains:

from PIL import ImageGrab
image = ImageGrab.grab()
image.save('image.jpg')

and it works fine. Now I want to use ImageGrab in another .py file. I create a new.py file and copy paste the same code.

from PIL import ImageGrab
image = ImageGrab.grab()
image.save('sc.jpg')

Suddenly I get this error:

Traceback (most recent call last):
File "c:/Users/Me/Desktop/new.py", line 1, in <module> 
    from PIL import ImageGrab 
File "C:\python\lib\site-packages\PIL\ImageGrab.py", line 23, in <module> 
    from . import Image 
File "C:\python\lib\site-packages\PIL\Image.py", line 48, in <module> 
logger = logging.getLogger(name) 
AttributeError: module 'logging' has no attribute 'getLogger'

It doesn't matter where I'm trying to import ImageGrab from PIL, it gives me that error in every single file, except the one file that already had it imported and was working before.

How can I fix that?

🌐
Fast.ai
forums.fast.ai › part 1 (2018)
AttributeError: module ‘PIL.Image’ has no attribute ‘register_extensions - Part 1 (2018) - fast.ai Course Forums
January 31, 2018 - I had similar issue. Next time, you start your colab VM, be sure to comment out the following two lines (i.e do not run them) · I also spent the few hours searching, for the cause. I think now that I have found the issue. There is actually no function with the name register_extensions() but ...
🌐
PyPI
pypi.org › project › pillow › 2.5.2
pillow · PyPI
+ Renamed some internal functions to avoid potential build problem on Mac OS X. + Added DL_EXPORT where relevant (for Cygwin, based on input from Robert Yodlowski) + (re)moved bogus __init__ call in BdfFontFile (bug spotted by Fred Clare) + Added "ImageGrab" support (Windows only) + Added support for XBM hotspots (based on code contributed by Bernhard Herzog). + Added write support for more TIFF tags, namely the Artist, Copyright, DateTime, ResolutionUnit, Software, XResolution and YResolution tags (from Greg Couch) + Added TransposedFont wrapper to ImageFont module + Added "optimize" flag to GIF encoder. If optimize is present and non-zero, PIL will work harder to create a small file.
      » pip install pillow
    
Published   Aug 13, 2014
Version   2.5.2
🌐
Technologytales
technologytales.com › attributeerror-module-pil-has-no-attribute-image
AttributeError: module 'PIL' has no attribute 'Image' | Technology Tales
That sorted it, and I must have run into trouble with PIL.ImageFilter too, since I now load it in the same manner. In both cases, I could just refer to Image or ImageFilter as I required and without the dot syntax.
🌐
GitHub
github.com › python-pillow › Pillow › issues › 2720
AttributeError: module 'PIL.Image' has no attribute 'load' · Issue #2720 · python-pillow/Pillow
November 2, 2022 - Traceback (most recent call last): File "D:/Projects/Python/Fproject.py/src/main.py", line 20, in PIL.ImageChops.difference(hspointer, currents).getbbox() is None File "C:\Users\User\AppData\Roaming\Python\Python36\site-packages\PIL\ImageChops.py", line 101, in difference image2.load() AttributeError: module 'PIL.Image' has no attribute 'load' ... import PIL.Image import PIL.ImageGrab import PIL.ImageChops import math, operator running = True boxhs = (828, 0, 1920, 90) hspointer = PIL.Image.open("homescreen.png") currents = PIL.Image def takeShot(): currents = PIL.ImageGrab.grab(boxhs).save("screen_capture.png", "PNG") takeShot() hstry = hspointer.crop(boxhs) hstry.save("try.png", "PNG") def compare(image1, image2): PIL.ImageChops.difference(image1, image2).getbbox() is None def mainloop(): while(running): takeShot() if(compare(hspointer, currents)): break mainloop()
Author   skullhood
🌐
GitHub
github.com › python-pillow › Pillow › issues › 901
Cannot from PIL import ImageGrab · Issue #901 · python-pillow/Pillow
September 14, 2014 - from PIL import ImageGrab Traceback (most recent call last): File "", line 1, in File "build/bdist.macosx-10.9-intel/egg/PIL/ImageGrab.py", line 26, in ImportError: No module named _grabscreen
Author   travellers
🌐
Reddit
reddit.com › r/learnprogramming › "module 'pil.image' has no attribute 'show'", but pil is working as expected.
r/learnprogramming on Reddit: "module 'PIL.Image' has no attribute 'show'", but PIL is working as expected.
January 16, 2024 -

SOLVED: Turns out BYU wrote a library specifically for the course which replaces PIL's Image, despite them giving explicit instructions to use PIL. Disregard if not specifically working on project one of CS111 at BYU. If you happen to be doing so, go look at the slides for lecture 7. You will need to import the byuimage library, which is not included in any of the distribution code, even though PIL imports are.

Hey guys! I'm working on some projects necessary to get a class waived at the school I'll (pending aceptance) be going to next fall. My experience with python is, well, very little, but the intro class uses python so I'm doing the work in Python.

The first project entails a simple "image processing" program. I've got to the first point to run a pytest (I have zero prior experience with pytest, so if I've done something done there, my bad), which is just to open and display the passed image. Program works as intended, but when I run the pytest written by the school, I get the following error.

__test_display_image ______________________________
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x0000024D0468D2D0>
@max_score(20)
def test_display_image(monkeypatch):
    observed = None
  @functools.wraps(Image.show)
E       AttributeError: module 'PIL.Image' has no attribute 'show'
test_project1.py:23: AttributeError

At first, I assumed that Pillow wasn't getting imported correctly, but the import line is the same in teh pytest as in the program.

from PIL import Image

After a good deal of googling, I've found similar looking errors dealing with other methods of Image, but none concerning .show, and they all have wildly different reasons, so I'm at a bit of a loss. The pytest and program files are in the same directory. I'm sure it's something dumb, but I'm not really sure what else to look at, so I'd love to have my dumb mistake pointed out! Thank you all!

Pytest code

from PIL import Image
from byu_pytest_utils import max_score, run_python_script, test_files
import functools import pytest

def assert_equal(observed: Image, expected: Image):
    assert observed.width == expected.width assert observed.height ==             
expected.height for y in range(observed.height):
        for x in range(observed.width): 
            observed_pixel = observed.get_pixel(x, y) expected_pixel =                     
        expected.get_pixel(x, y)
            assert observed_pixel.red == expected_pixel.red, f"the pixels at 
        ({x}, {y}) don't match" 
            assert observed_pixel.green == expected_pixel.green, f"the pixels at                 
         ({x}, {y}) don't match" 
            assert observed_pixel.blue == expected_pixel.blue, f"the pixels at                 
        ({x}, {y}) don't match"

@max_score(20) def test_display_image(monkeypatch):
    observed = None @functools.wraps(Image.show) 

    def patched_Image_show(self):
        nonlocal observed
        observed = self 
        monkeypatch.setattr(Image, 'show', patched_Image_show)

        run_python_script('image_processing.py', '-d',
                  test_files / 'explosion.input.png')

        if observed is None:
            pytest.fail('No Image was shown')

        assert_equal(observed, Image(test_files / 'explosion.input.png'))

Program code (though I don't think it should matter)

import sys
from PIL import Image

def main():
if not validate_command(sys.argv):
    return

run_command()

def validate_command(args):
    try: 
        if args[1][0:1] == '-' and args[2] != None:
            print(f"Running image processor with aruments {args[1]}, {args[2]}")         
            return True
        else:
        print("Invlaid arguments. Usage: image_processing.py <operation>     
         [<argument 1> <argument 2> ...]") 
    except: print("Invlaid arguments. Usage: image_processing.py <operation> 
        [<argument 1> <argument 2> ...]")
            return False

def display(image):
    image.show()

def run_command():
image = Image.open(sys.argv[2])
commands[sys.argv[1]](image)

commands = {"-d": display}

main()

(Pasting into reddit messed up the formatting, so it's possible I made a mistake when correcting the formatting)

🌐
Pillow Documentation
pillow.readthedocs.io › en › stable › reference › ImageGrab.html
ImageGrab module - Pillow (PIL Fork) 12.2.0 documentation
The ImageGrab module can be used to copy the contents of the screen or the clipboard to a PIL image memory. Added in version 1.1.3. PIL.ImageGrab.grab(bbox=None, include_layered_windows=False, all_screens=False, xdisplay=None, window=None)[source]¶ · Take a snapshot of the screen.