10

I want to use qt with python. "import qt" return me :"ImportError: No module named qt". I already instaled pyqt.

what I hve to install in order to activate "import qt"

Thank You

4
  • This is really a google question. I would say read this: cs.usfca.edu/~afedosov/qttut Commented Apr 23, 2011 at 19:59
  • 3
    Also, I would consider PySide. Commented Apr 23, 2011 at 19:59
  • 3
    Eli's answer is correct if you have installed PyQt4. You are probably looking at an example that uses PyQt3, which had a qt module you could import. Commented Apr 23, 2011 at 20:00
  • @Michael: insightful catch ;-) Commented Apr 23, 2011 at 20:02

2 Answers 2

12

The current PyQt comes in the PyQt4 package, which has several modules. You almost always need to start with:

from PyQt4 import QtCore
from PyQt4 import QtGui

Add other imports as necessary if you need additional sub-modules of PyQt (like QtNetwork, QtSql etc).


Tip for the future: find the lib/site-packages library of your Python installation and look at the packages in there if you're not sure about the name after installing.

Also, arm yourself with a PyQt tutorial - any decent one covers this in the first few paragraphs.

Sign up to request clarification or add additional context in comments.

2 Comments

Also, from PyQt4 import Qt. Contains the most commonly-used classes and is shorter to type.
@delnan: I must confess that personally I import * when using PyQt because all classes start with Q anyway, and it really saves a lot of typing for large amounts of code
3

import PyQt4 works for me fine.

1 Comment

import PyQt4 doesn't suffice to make sure that PyQt has been successfully linked to a working Qt installation. Either can be broken (linking or the Qt installation). Doing from PyQt4 import QtGui does expose such issues, e.g., dlopen failures.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.