PyQt4 and Python 3.2 on OS X - pyqt4

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 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__)

Related

QsciScintilla on Pyqt4 for python35 error (unofficial whl)

I want to use pyqt4 on python35. However, the latest official release supports py=<34
So I found this university website https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyqt4
which unofficially extended support for later versions including python35
My problem is that QsciScintilla is not working. I tried to run this code:
import sys
from PyQt4.QtGui import QApplication
from PyQt4 import QtCore, QtGui, Qsci
from PyQt4.Qsci import QsciScintilla
if __name__ == "__main__":
app = QApplication(sys.argv)
editor = QsciScintilla()
editor.show()
sys.exit(app.exec_())
The window becomes unresponsive then crashes:
Process finished with exit code -1073740771 (0xC000041D)
The reason I want to use pyqt4 on python3.5 is that I have a quit big application built on pyqt4
and I want to upgrade python version of the project to 35
I moved to PyQt5. It is always not a good idea to use an unofficial package.

DLL Load Fail While Importing QtCore, QtGui

guys
I recently heard about PyQt4 and decided I should give it a try, however, importing gave me some errors. When I tried importing QtCore and QtGui, I received this error:
from PyQt4 import QtCore, QtGui
ImportError: DLL load failed: The specified module could not be found.
I am using python 3.6.0 on my windows 32 bit computer
I installed pyqt4 by using
pip install pyqt4-4.11.4-cp36-cp36m-win32.whl
To solve this problem I looked into my site-packages and I did see
You should use PyQt5. I know it doesn't have QWebView, but it has a extra module called QWebEngineView. You can install it by running this in the terminal:
pip install PyQtWebEngine. This is the code I use:
import sys
from PyQt5.QtCore import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtWidgets import QApplication
url = "https://stackoverflow.com/"
app = QApplication(sys.argv)
web = QWebEngineView()
web.load(QUrl(url))
web.setZoomFactor(2)
web.zoomFactor()
web.show()
sys.exit(app.exec_())

PyQt5 ImportError after running standalone executable created by PyInstaller

I have a fully working PyQt5 project, now trying to make a standalone executable that is preferably OS independent.
I am using PyInstaller-3.2 in ubuntu 14.04 for this purpose. Tried the following command.
pyinstaller --additional-hooks-dir=. -F <file-path>
Everything works, but when I have run the particular executable, received the following ImportError:
ImportError: No module named PyQt5
Later, I have found out that I need to include some PyInstaller hooks to import PyQt5
As my related imports throughout the project were:
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5 import QtWidgets, uic
from PyQt5.QtCore import QThread
So, I have added some hooks namely hook-PyQt5.QtCore.py, hook-PyQt5.QtGui.py, hook-PyQt5.QtWidgets.py, hook-PyQt5.uic.py which content is more or less like below:
hiddenimports = ["PyQt5.QtCore.*"]
Then I run the PyInstaller command.
pyinstaller --additional-hooks-dir=. -F <file-path>
But, unfortunately, I got the same importError.
What I am doing wrong here?

Error "Could not find any typelib for Gtk" with Python3 and GTK3

I cannot make Python3 work with GTK3. I'm in a cluster context and I had everything recompiled from the sources.
When I run a simple example :
from gi.repository import Gtk
win = Gtk.Window()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
I have the following error :
ERROR:root:Could not find any typelib for Gtk
Traceback (most recent call last):
File "gtk3_example.py", line 2, in
from gi.repository import Gtk
ImportError: cannot import name 'Gtk'
There are typically additional packages to install depending on what you want to introspect. The one I found that was crucial was gir1.2-gtk-3.0 (or 2.0 depending which version you are coding against).
The problem is due to the compiled version of GTK3 that was not referenced in gobject-introspection.
It is simple to check the problem by listing the .typelib files in gobject-introspection
$ which g-ir-scanner
/Produits/publics/x86_64.Linux.RH6/gobject-introspection/1.40.0/bin/g-ir-scanner
$ ls /Produits/publics/x86_64.Linux.RH6/gobject-introspection/1.40.0/lib/girepository-1.0/
cairo-1.0.typelib fontconfig-2.0.typelib GIRepository-2.0.typelib GModule-2.0.typelib win32-1.0.typelib xlib-2.0.typelib
DBus-1.0.typelib freetype2-2.0.typelib GL-1.0.typelib GObject-2.0.typelib xfixes-4.0.typelib xrandr-1.3.typelib
DBusGLib-1.0.typelib Gio-2.0.typelib GLib-2.0.typelib libxml2-2.0.typelib xft-2.0.typelib
The problem should be solved by recompiling GTK (and its dependencies) with the configure option --enable-introspection=yes.
Try using the following code:
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import GTK

PyQt4 cannot import QtGui but can import QtCore

I installed python3.3 x86 (official python.org installer) on this windows 7 32-bit
then installed PyQt4-4.10 for python3.3 windows x86 from here PyQt4-4.10-gpl-Py3.3-Qt5.0.1-x32-2.exe, an official installer too, a full PyQt4 installation (including Qt Runtime)
I double checked that both python and PyQt4 are on $PATH
but it seems I can import some packages(eg, QtCore) but not others (eg, QtGui)
although they are side by side in the same path
>>> from PyQt4 import QtCore
>>> QtCore.__file__
'C:\\Python33\\lib\\site-packages\\PyQt4\\QtCore.pyd'
>>> from PyQt4 import QtGui
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
from PyQt4 import QtGui
ImportError: DLL load failed: The specified module could not be found.
>>> import os
>>> os.path.exists('C:\\Python33\\lib\\site-packages\\PyQt4\\QtGui.pyd')
True
>>> from PyQt4 import Qt
>>> from PyQt4 import QtXml
>>> from PyQt4 import QtNetwork
>>> from PyQt4 import QtDesigner
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
from PyQt4 import QtDesigner
ImportError: DLL load failed: The specified module could not be found.
>>> os.path.exists('C:\\Python33\\lib\\site-packages\\PyQt4\\QtDesigner.pyd')
True
Qt5Gui.dll depends on D3dCOMPILER_43.dll, which is part of DirectX. You can update your installation with the DirectX End-User Runtime Web Installer.
If you don't like to install the whole DirectX you can do the following:
First download the Directx redistributable: http://www.microsoft.com/en-us/download/details.aspx?id=8109 (this is a kind of self extracting MS-Cabinet-file)
Then in Linux for example (Debian based - should work similar on other distros):
sudo apt-get install cabextract
mkdir cabs
cabextract -d cabs -F JUN2010\* directx_Jun2010_redist.exe
cd cabs
mkdir x64
cabextract -d x64 -F \*.dll *_x64.cab
In Windows you can extract cab-files for example with Winrar. Some windows versions included a command line utility for cab-files - I think it was called extract.

Resources