2

I have installed the PIL library using pip like this:

pip install Pillow

and it's working fine also showing library path in interrupter PyCharm Options.

But Autocomplete is not working, I tried to turn off the Power Save Mode and added custom virtual env, but it's still not working.

Have a look Image

Any idea why it does not work?

So it's now showing sub methods :

from PIL import Image
im = Image.open("bride.jpg")
im.rotate(45).show()
Earon
  • 733
  • 1
  • 12
  • 18
  • Possible duplicate of [Why isn't PyCharm's autocomplete working for libraries I install?](http://stackoverflow.com/questions/28677670/why-isnt-pycharms-autocomplete-working-for-libraries-i-install) – manniL May 15 '16 at 15:09
  • Yes this is what i defined that virtual env also not working. – Earon May 15 '16 at 15:10
  • How do you expect PyCharm to know what type of object `mandeep` is? – Mark Dickinson May 15 '16 at 15:14
  • I have seen PIL Library have show option when you use Image.open("ad") but it's now showing me when i type (.) Here are document i am looking but how do i know what methods provider by pillow library ? or i have to look documents every time. https://pillow.readthedocs.io/en/latest/handbook/overview.html#image-display – Earon May 15 '16 at 15:17

2 Answers2

9

PyCharm doesn't know the type of im as the library has no type hints for Image.open(). So I decided to set local type hint like this:

your_image = Image.open(path_to_image) # type: Image.Image
your_image.now_shows_list = True

For complete reference look at JetBrains type hints documentation.

SBKubric
  • 106
  • 1
  • 5
0

The problem is that:

  • PIL.Image is a module (normally lowercase)
  • The module contains a function called open()
  • open() returns a Type of PIL.Image.Image
  • PyCharm does not realise it returns this type unless you tell it (I don't why).

https://pillow.readthedocs.io/en/3.0.x/handbook/tutorial.html#using-the-image-class

To avoid clashes with my project on the name "Image", as well as to stay Pep8 and adhere to google's style guide, I opted for:

    from PIL import Image as PilImage

    my_image: PilImage.Image = PilImage.open("my_image.png")
    my_image.show()

Running on python 3.8.2

Robin Carter
  • 139
  • 9