python-pptx icon indicating copy to clipboard operation
python-pptx copied to clipboard

Autocompletion in Pycharm

Open strupy91 opened this issue 4 years ago • 2 comments

Has anyone a hint for autocompletion in Pycharm with pptx library. Other installed libraries working fine and it works in terminal. Maybe someone had the same problem? I tried different interpreter (2.7, 3.8, 3.10), installing with pip and github. Different versions from pptx. Windows, Linux. Pycharm, Visual Studio. But nothing worked.

Not working: pptx

working: pptx2

strupy91 avatar Oct 20 '21 08:10 strupy91

Not a solution but a hint as to possible cause, pptx.Presentation is a function that returns a pptx.presentation.Presentation object: https://github.com/scanny/python-pptx/blob/master/pptx/api.py#L18.

So PyCharm might need some help making that connection. Some folks seem to have gotten it to work by importing both, but that might be a little tricky since you want to call the (factory) function and not construct the object directly: https://stackoverflow.com/a/52466366/1902513

scanny avatar Oct 20 '21 16:10 scanny

Type annotations will help, but name collision indeed may introduce some confusion.

import pptx
from pptx.presentation import Presentation

with open("example_slide.pptx", "rb") as f:
    presentation: Presentation = pptx.Presentation(f)

sergey-serebryakov avatar Nov 29 '23 23:11 sergey-serebryakov