PyCharm auto-complete does not work with pygame

I just installed PyCharm Community Edition 3.4.1 and tried to create a simple pygame project in it. I found that code completion is done in a weird way. In this case:

from pygame import event event. 

when i type event. completion popup using event methods. But in the second case:

 import pygame pygame.event. 

the popup contains only the object methods.

How can I learn the autocomplete tool to go deeper into the library?

+5
source share
3 answers

Besides creating your own skeletons , you cannot. You can make pycharm a little better than code completion if you include the following:

enter image description here

But other than that, you're out of luck. Python is difficult to execute to complete the code because its dynamic language, and stubs (skeletons) do not exist for everything.

+4
source

I tried Daid to answer (by removing try / except in init .py) and it did not work, but it was very close! Here's how you can fix it specifically for pygame:

  • Go to the pygame folder and open init .py in a text editor
  • Go to the import section with try / except clauses (around line 109).
  • Change pygame.module import format to pygame import module for the modules you want

For example, change

 try: import pygame.event 

to

 try: from pygame import event 

Restart PyCharm and it should work :)

+3
source

This is due to how pygame is created.

:

 python\Lib\site-packages\pygame\__init__.py 

The file contains the following construction:

 try: import pygame.cdrom except (ImportError,IOError):cdrom=MissingModule("cdrom", geterror(), 1) 

That allows you to skip import. However, this confuses picharm. Uninstall try + except for the pycharm autocompletion fix.

+1
source

Source: https://habr.com/ru/post/1204323/


All Articles