scanny / python-pptx

Create Open XML PowerPoint documents in Python
MIT License
2.36k stars 511 forks source link

Autocompletion in Pycharm #755

Open strupy91 opened 2 years ago

strupy91 commented 2 years ago

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

scanny commented 2 years ago

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

sergey-serebryakov commented 9 months ago

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)