PyQt4 and Python 3.2 on OS X
I've successfully installed Qt4.7.3, Python 3.2, SIP, & PyQt4. Or I think I do? I can
import PyQt4
without any issues but when I try开发者_StackOverflow社区 to run this:
#!/usr/bin/env python3
import sys
from PyQt4 import QtGui
app = QtGui.QApplication(sys.argv)
widget = QtGui.QWidget()
widget.resize(250, 150)
widget.setWindowTitle('simple')
widget.show()
sys.exit(app.exec_())
I get this error:
Traceback (most recent call last):
File "./simple.py", line 6, in
<module>
from PyQt4 import QtGui
ImportError: cannot import name QtGui
I've checked the paths and they seem to be fine but when looking for the components I can't find them? I do have libQt.a and libQtCore.a where I assume those components would be. I just can't seem to access them.
Any ideas?
Thanks.
If you use #!/usr/bin/env python3
you can not be sure which version of python starts up. For testing you should directly use python3.2
!
Since import PyQt4
works and from PyQt4 import QtGui
not, it is likely that the files in the PyQt4 module directory are misplaced.
The QtGui.so
file needs to resist directly in the PyQt4 directory!
On GNU Systems this directory can be found at /usr/lib/python3/dist-packages/PyQt4/
and on Windows at %SystemDrive%23/Python32/Lib/site-packages/PyQt4/
.
This might help finding the directory on Mac OS:
import PyQt4
print(PyQt4.__file__)
精彩评论