Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm autocomplete does not work with pygame

I've just installed PyCharm Community Edition 3.4.1 and tried to make a simple pygame project in it. I found that code completion runs in a weird way. In this case:

from pygame import event
event.

when I type event. a completion popup with event methods shows immediately. But in the second case:

import pygame
pygame.event.

a popup contains only object methods.

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

like image 805
Ivan Smirnov Avatar asked Oct 09 '14 11:10

Ivan Smirnov


People also ask

Why Autocomplete is not working in PyCharm?

If code completion doesn't work, this may be due to one of the following reasons: The Power Save Mode is on (File | Power Save Mode).

Does pygame work with PyCharm?

To install pygame, move the mouse over the red underlined area and click on “install package pygame“. Wait for Pycharm to install pygame and that's it !

How do I enable auto suggestions in PyCharm?

Press Ctrl+Alt+S to open the IDE settings and select Editor | General | Code Completion. Under Machine Learning-Assisted Completion, enable the Sort completion suggestions based on machine learning option, and select the languages for which you want to use ML completion.


2 Answers

Other than creating your own skeletons, you can't. You can make pycharm a little better a code completion if you enable the following:

enter image description here

But other than that, you're out of luck. Python is hard to make code completion for because its a dynamic language, and stubs (skeletons) don't exist for everything.

like image 189
Games Brainiac Avatar answered Oct 01 '22 09:10

Games Brainiac


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

  1. Go to your pygame folder and open init.py in a text editor
  2. Navigate to the import section with the try/except clauses (around line 109)
  3. Change the format from import pygame.module to from 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 :)

like image 36
Bee Kay Avatar answered Oct 01 '22 10:10

Bee Kay