SaltyCrane Blog — Notes on JavaScript and web development

How to get code completion for PyQt using Pydev

Because PyQt doesn't come with the .py source files which Pydev needs for code completion, you need to add the PyQt modules as a "forced builtin lib". See the following FAQs at the pydev website: http://pydev.sourceforge.net/faq.html#ref_22 and http://pydev.sourceforge.net/faq.html#ref_15
 
Here are the steps:
  1. Go to "Window" -> "Preferences..." -> "Pydev" -> "Interpreter - Python"
  2. In the "Forced builtin libs" section, click "New..."
  3. Type in "PyQt4" and click "OK".
  4. Click "OK" to close the Preferences window.
Note: If you installed PyQt after installing Pydev, you will probably have to update the PYTHONPATH with the path to the PyQt libraries. You can do this easily by "Remove"ing the python interpreter and then re-adding it in again. (For reference, I am using Eclipse 3.2.2, Pydev 1.3.4, Python 2.5.1, and PyQt 4.2.3)

Comments


#1 Andrea Grandi commented on :

Code completion now works fine for me, except for some classes. For example:

if I write: from PyQt4 import

it only shows me two class available: QtCore and QtGui, for example I cannot see QtNetwork, but if I write it by hand, my code execute it without problems.

Any suggestion about this problem?


#2 Octavia commented on :

Thanks for writing this.


#3 Jonathan Blakes commented on :

nice one


#4 Saatvik commented on :

For some reason, this still doesn't work for me. I'm using the eclipse that comes with Python(x,y) but I don't think that should make a difference. I've tried adding PyQt4 to both the PYTHONPATH and the Forced Builtin libs and nothing works. Also tried reinstalling PyQt4 without any success.

Thanks


#5 Al Dunstan commented on :

I've had the same problem as Saatvik. I ran Eclipse from the command line, however, and noticed that it was throwing a ClassCastException when trying to do the completion, trying to cast a SystemASTManager to an ASTManager. I'm going to post the bug at Pydev shortly.


#6 Sebastián commented on :

Works like a charm, thank you :) I was thinking of using eric4, but now I think I'll stick to Eclipse, the troll at Eric's splashscreen scares the hell out of me.


#7 bswix commented on :

This works for auto-completion, but I cannot seem to get any call tip for function arguments? Does anyone have this working?


#8 Auspex commented on :

Thanks for this. It wasn't quite that simple... I had to enumerate every single PyQt4 import, but that beats having 200+ errors in a very simple project. And there's code completion!


#9 Al Banna Techno commented on :

i solve this problem just do next :

# Solved By Al Banna Techno  
from PyQt4.QtGui import *  
from PyQt4.Qt import *  
import sys  
run=False  
#we tricking on program to not making an error  
if run==True:  
from PyQt4.Qt.__init__ import *  
from PyQt4.QtGui.__init__ import *  
from PyQt4.__init__ import *

disqus:2798331066