PyQt4 cannot import QtGui but can import QtCore - pyqt4

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.

Related

Why does command prompt import differ from sublime text import?

I have installed with pip several packages (numpy/pandas/blpapi/pyarrow). I work with a Windows 64-bit machine, python3.6 in a sublime environment.
While all packages are shown as correctly imported in the command prompt, some packages are not found by my sublime scripts.
To try and remedy this problem, I used sys.path.insert and changed the names of my scripts, to no avail. The traceback below describes what I'm seeing:
Code in Command Prompt:
>>> import pyarrow
>>> import pandas
>>>
Code in Sublime (better_name.py):
print('Hi')
import numpy
import pandas
Output of better_name.py:
Hi
Traceback (most recent call last):
File "C:\Users\Documents\better_name.py", line 4, in <module>
import pandas
ModuleNotFoundError: No module named 'pandas'
Obtaining the paths in Command Prompt:
>>> import os
>>> import numpy
>>> path = os.path.dirname(numpy.__file__)
>>> print(path)
C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\numpy
>>> import pandas
>>> path = os.path.dirname(pandas.__file__)
>>> print(path)
C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas
Trying to use sys.path.insert :
print('Hi')
import sys
import numpy
import os
sys.path.insert(1, r"C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas")
Output:
C:\Users\Documents>better_name.py
Hi
Traceback (most recent call last):
File "C:\Users\Documents\better_name.py", line 7, in <module>
import pandas
ModuleNotFoundError: No module named 'pandas'
I get the same results whether I change the argument in sys.path.insert to 0.
The issue seems to be that your default version of python points to the 32-bit version - i.e. when you say python your windows system executes the 32 bit version.
One workaround is to specify the full path of your 64 bit version - i.e. launch your script as
C:\PATH\TO\64-BIT-VERSION\PYTHON.EXE your_script.py
from the command line.
The other option is to set your windows environment variables to point to the 64 bit version by default. This link should help

PyQt4 installation on Linux

Please help to finish installation of PyQt.
So I think I successfully installed SPI and PyQt as it is mentioned in the reiverbankcomputing. (https://www.riverbankcomputing.com/software/pyqt/download)
(at least no errors where raised during installation).
However when in python shell I import PyQt, python does not recognize it:
>>> from PyQt4 import QtCore, QtGui
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named PyQt4
To my opinion the issues is in PATH variable. I am not root in Linux, so installed python only for my user.
I assume I need to setup some environment variables, but don’t know which ones.
Can you please help?
P.S. My linux is not conntected to Web, so need to download all packages seperatly.

Install PyQt4 via conda for caffe model

When I try to run the SEC caffe model on from here: https://github.com/kolesman/SEC
I geht the error: ImportError: No module named PyQt4
python demo.py --model SEC.caffemodel --image /data/out/dataset/center/1475186965759787059.jpg --smooth --output result.png
Traceback (most recent call last):
File "demo.py", line 2, in <module>
import pylab
File "/home/ec2-user/anaconda2/lib/python2.7/site-packages/pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "/home/ec2-user/anaconda2/lib/python2.7/site-packages/matplotlib/pylab.py", line 274, in <module>
from matplotlib.pyplot import *
File "/home/ec2-user/anaconda2/lib/python2.7/site-packages/matplotlib/pyplot.py", line 114, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/home/ec2-user/anaconda2/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "/home/ec2-user/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_qt5agg.py", line 16, in <module>
from .backend_qt5 import QtCore
File "/home/ec2-user/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_qt5.py", line 31, in <module>
from .qt_compat import QtCore, QtGui, QtWidgets, _getSaveFileName, __version__
File "/home/ec2-user/anaconda2/lib/python2.7/site-packages/matplotlib/backends/qt_compat.py", line 137, in <module>
from PyQt4 import QtCore, QtGui
ImportError: No module named PyQt4
In this stackoverflow thread they just mention that you can run
conda install pyqt
which results in the following output:
conda install pyqt
Fetching package metadata .......
Solving package specifications: ..........
# All requested packages already installed.
# packages in environment at /home/ec2-user/anaconda2:
#
pyqt 5.6.0 py27_0
Which indicates that I have version 5.6 and not version 4. But I could not find any solution how to downgrade to pyqt4.
so you can Uninstall pyqt5 and download PyQt4 and installed manually
The second option is to modify the code and replace PyQt4 by pyqt5 just pay attention to one thing that the classes in pyqt5 are the same but the irritation is bit different so you may get that specific model doesn't exist in this case check on manual of pyqt5 and fix it
I hope my answer is clear
It looks like the latest version of anaconda forces install of pyqt5.6 over any pyqt build, which will be fatal for your applications. In a terminal, Try:
conda install --channel https://conda.anaconda.org/conda-forge pyqt
conda install -c anaconda pyqt=4.11.4
It will prompt to downgrade conda client. After that, it should be good.

PyQt5 - Error import QtWidgets QtGui

I'm running Ubuntu 13.10 (python-3.3.2+) . I've installed Qt5.2.1 (linux installer) , SIP 4.15.5 & PyQt5 both from source of the official site.
PyQt5 build :
The Qt qmake is located here
jeby6372#mercure:~$ ls /opt/Qt/5.2.1/gcc_64/bin
assistant qdbus qml1plugindump qmlviewer
designer qdbuscpp2xml qml2puppet qtpaths
lconvert qdbusviewer qmlbundle rcc
linguist qdbusxml2cpp qmlimportscanner syncqt.pl
lrelease qdoc qmlmin uic
lupdate qhelpconverter qmlplugindump xmlpatterns
moc qhelpgenerator qmlprofiler xmlpatternsvalidator
pixeltool qmake qmlscene
qcollectiongenerator qml qmltestrunner
My python path
jeby6372#mercure:~$ echo $PYTHONPATH
:/usr/lib/python3.3/site-packages
Qt5 libraries (shorten list for display purpose):
jeby6372#mercure:/opt/Qt/5.2.1/gcc_64/lib$ ls
cmake libQt5Positioning.so.5
libicudata.so.51 libQt5Positioning.so.5.2
libicudata.so.51.1 libQt5Positioning.so.5.2.1
libqgsttools_p.so libQt5PrintSupport.so.5.2.1
libqgsttools_p.so.1 libQt5QmlDevTools.a
libQt5CLucene.so.5.2 libQt5QuickParticles.so.5.2.1
libQt5Concurrent.so.5.2 libQt5QuickTest.la
libQt5Concurrent.so.5.2.1 libQt5QuickTest.prl
libQt5Core.so.5.2.1 libQt5Script.prl
libQt5DBus.la libQt5Script.so
.......
libQt5Multimedia.so libQt5WebKit.prl
libQt5Nfc.la libQt5Widgets.so.5.2.1
libQt5Nfc.prl libQt5X11Extras.la
libQt5Nfc.so libQt5X11Extras.prl
libQt5Nfc.so.5 libQt5X11Extras.so
libQt5Nfc.so.5.2 libQt5X11Extras.so.5
libQt5OpenGLExtensions.a libQt5X11Extras.so.5.2.1
libQt5OpenGLExtensions.la libQt5Xml.la
libQt5OpenGL.so libQt5XmlPatterns.so.5
libQt5OpenGL.so.5 libQt5XmlPatterns.so.5.2
libQt5OpenGL.so.5.2.1 libQt5Xml.prl
libQt5Platfor
libQt5PlatformSupport.prl libQt5Xml.so.5.2
libQt5Positioning.so
I ran the following commands in the source directory extracted from the official PyQt-gpl-5.2.1.tar.gz tarball :
python3 configure.py --qmake /opt/Qt/5.2.1/gcc_64/bin/qmake # My PyQt5 location
sudo make
sudo make install
Issue:
I can only import a restricted set of modules
>>> from PyQt5.QtCore import *
>>> from PyQt5.QtNetwork import *
>>> from PyQt5.QtXmlPatterns import *
>>> from PyQt5.Qt import *
>>> from PyQt5.QtGui import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'PyQt5.QtGui'
>>> from PyQt5.QtWidgets import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'PyQt5.QtWidgets'
I can import QtCore, QtNetwork ... as listed in /usr/local/python3.3/sites-packages/PyQt5 :
jeby6372#mercure:/usr/lib/python3.3/site-packages/PyQt5$ ls
__init__.py QtCore.so QtDBus.so QtNetwork.so Qt.so QtXmlPatterns.so uic
But I can't import QtWidgets, QtGui .. and so on.
It seems that the PyQt5 libraries are not all copied here.
The same problem is described in this post ... but unfortunately with no response from the RiverBanck's team :
Any idea?
Missing package
Install the missing libgl1-mesa-dev dependency as suggested by mata. It's a free implementation of the OpenGL API.
Build
sudo apt-get install libgl1-mesa-dev
Create or clean up your PyQt5 compilation environment and build it according to the regular procedure.
Alternative
If this fix doesn't solve your problem, install the libgl1-mesa-glx package (GLX runtime) and the libgl1-mesa-dri (drawing accelerator) if they are also missing and proceed with Build instructions.
Hope this help.

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

Resources