Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt4 names showing as undefined in eclipse, but it runs fine

I am using Eclipse 3.7.1 with the latest PyDev add-in for Python coding. I am using PyQt4. At the top of my file I have:

from PyQt4.QtCore import *
from PyQt4.QtGui import *

In addition, I have the PyQt4 tree included in the Project Explorer listing. However, eclipse still thinks the names like QMainWindow are undefined. The code runs fine. How may I get eclipse to recognize those names.

Thanks

like image 854
Kevin Buchs Avatar asked Nov 10 '11 15:11

Kevin Buchs


1 Answers

PyQt is actually a wrapping of C++ Qt libraries. So they are not .py files and PyDev can't analyze them to get what is in them. You need to add PyQt4 in the Forced Builtins tab, so that PyDev can use a Python shell to "look into" those libraries and know what is in them. That will also give you code-completion for PyQt.

Apart from that, it is usually not a good practice to use from foo import *. You'll be importing everything inside your namespace and you wouldn't know which is coming from where. Moreover you might have name clashes that mask each other. Though it is unlikely with PyQt, still I'd suggest you get used to from PyQt4 import QtGui, QtCore and reference classes like QtGui.QMainWindow.

like image 96
Avaris Avatar answered Oct 21 '22 15:10

Avaris