Setting up PyQt4 for win7 - python

This is dumb, but I've just installed python and PyQt4 on my win7 laptop. However, when I try to import PyQt4, python can't find that module.
I followed the directions here:
http://qt-project.org/doc/qt-4.8/install-win.html
I've set up the Path environment variable. I ran the configure but my lib dir is still empty. I'm just not sure what I'm missing. Any help would be appreciated.
Cheers.

You need to install PyQt4, not Qt4.
http://www.riverbankcomputing.com/software/pyqt/download

Related

I am receiving and import error when trying to import cv2 in python (Ubuntu 18.04)

First of all, thank you very much for reading.
Some days ago I installed Python3 (3.6.9) and opencv 3.4.10 in an Ubuntu 18.04 desktop system. I needed to downgrade opencv to 3.4.0 after some compilation problems (not related to python3), so I removed opencv 3.4.10 by using the sudo make uninstall order, and tested that it was uninstalled as if I tried importing it in python I got the following error:
libopencv_hfs.so.3.4: cannot open shared object file: no such file or directory
I thought installing 3.4.0 version would solve the problem but now that it's installed, when I try to import it in a python3 script I am getting the same error. I think this error must be related to the way python3 references the import files. I think it's still pointing to the uninstalled version of 3.4.10, but I can not find the way to change it.
Could someone please help me with this issue?
Thank you very much.
Andrés.
Using a virtualenv would resolve the issue. Check this out on how to use : Installing packages using pip and virtual environments
Once you're done installing requirements in the virtualenv, run your python script there only to use the specified versions.
Hello again and thank you for you answers.
I have been able to solve the problem. Thought I had uninstalled the previous version of opencv, there was still a cv2.sofile in my python virtual environment path, and it had not been replaced by the new cv2.so, so python tried to import the old one instead of the new one.
The old cv2.so (the one that was referenced when I imported cv2 in python) was here --> ~/.virtualenvs/cv/lib/python3.6/site-packages/cv2.so
The cv2.so I wanted to be used when imported was here --> /usr/local/lib/python3.6/site-packages/cv2/cv2.so so I replaced the one in the virtual environment path with the one in the lib directory and that did the trick :)

How do I launch Pygubu with Anaconda 3 (Spyder)?

I am trying to use pygubu designer to make some interfaces. I am using Anaconda and my Python version is 3.7.6. The pygubu-designer.exe file is in the Scripts directory (C:\Users\user\Anaconda3\Scripts) but when I want to execute the application, an error code shows up saying the file is not found. Do you have any idea of what is causing this error ?
I installed pygubu via pip before... Thanks
With a little thinking I re intalled the pygubu module, and now it's working fine... Sorry for the inconvenience. Have a good day !

pyQt4 DLL load failed: The specified module could not be found

I have an issue using the pyQt4 library in Atom. I installed the package using the installation file from sourceforge. I have python 3.6 installed. This is the code I have now:
import sys
from PyQt4 import QtGui
Whenever I try to run this I get the following error:
File ".\test.py", line 4, in <module>
from PyQt4 import QtGui`
ImportError: DLL load failed: The specified module could not be found.
I already googled and found a few ways to fix this but none of the solutions worked for me. Here's what I have done so far:
-Confirmed all .dll files are in the main directory(no \bin directory)
-Confirmed both python and qt4 are 64bit.
-Created a an environment path in windows system pointing to qt4 directory
-Uninstalled and installed qt4 again
-Installed qt5 - got the same error.
-Confirmed python3.dll is present in python directory
Any idea what else might be the problem? Or perhaps I should just change to wxpython?
Thanks.
OK, I got it. I don't know why but I had to uninstall and re-install sip again.
I believe I installed pytq4 before installing sip and that didn't work well.
I uninstalled both pyqt4 and sip and installed sip -> pyqt4 in this order.
Hope this helps someone.

How to fix "could not find or load the Qt platform plugin windows" while using Matplotlib in PyCharm

I am getting the error "could not find or load the Qt platform plugin windows" while using matplotlib in PyCharm.
How can I solve this?
I had the same problem with Anaconda3 4.2.0 and 4.3.0.1 (64-bit). When I tried to run a simple program that uses matplotlib, I got this error message:
This application failed to start because it could not find or load the Qt platform plugin "windows"
Reinstalling the application may fix this problem.
Reinstalling didn't fix it.
What helped was this (found here):
Look for the Anaconda directory and set the Library\plugins subdir (here c:\ProgramData\Anaconda3\Library\plugins) as environment variable QT_PLUGIN_PATH under Control Panel / System / Advanced System Settings / Environment Variables.
After setting the variable you might need to restart PyCharm, if the change does not have an immediate effect.
Even though after that the command line Python worked, TexWorks (which uses Qt as well) displayed an error message very much like it. Setting the QT_PLUGIN_PATH to the directory containing TexWorks' Qt DLLs (here C:\Users\chris\AppData\Local\Programs\MiKTeX 2.9\miktex\bin\x64) fixed the problem for both programs.
If you want to visualize your matplotlibs in an alternative way, use a different backend that generates the graphs, charts etc.
import matplotlib
matplotlib.use('TKAgg')
This worked for me.
If you are running PyQt5 and PySide2, this solved the problem for me:
Copy the following files:
\Anaconda3\Lib\site-packages\PySide2\plugins\platforms\qminimal.dll
\Anaconda3\Lib\site-packages\PySide2\plugins\platforms\qoffscreen.dll
\Anaconda3\Lib\site-packages\PySide2\plugins\platforms\qwindows.dll
to:
\Anaconda3\Library\plugins\platforms\
I tried the following at Anaconda's prompt, and it solved this problem:
conda remove qt
conda remove pyqt
conda install qt
conda install pyqt
I found that this was being caused by having the MiKTeX binaries in my PATH variable; and the wrong Qt dll's were being found. I just needed to re-arrange the PATH entries.
(Dependency Walker is such a useful tool.)
I had a similar problem with PyCharm where things worked great in main run but not in debugger, getting the same error message. This happened for me because I had moved my Anaconda installation to a different directory. The debugger goes and checks a qt.conf file that is located at the same place as python. This location can be found by running import sys; print sys.executable. I found this solution through a pile of web searches and it was buried deep here. The qt.conf file needs to have correct paths for debugger to work.
My qt.conf files looks like this in notepad:
[Paths]
Prefix = E:/python/Anaconda3_py35/Library
Binaries = E:/python/Anaconda3_py35/Library/bin
Libraries = E:/python/Anaconda3_py35/Library/lib
Headers = E:/python/Anaconda3_py35/Library/include/qt
Just add a system variable:
QT_QPA_PLATFORM_PLUGIN_PATH
and set its value to
C:\Python34\Lib\site-packages\PyQt4\plugins\platforms
Voilà. Done
I have found a solution that worked for me. This solution includes a code snippet to add before you import any modules from Pyside2 or PyQt5 package. See "Qt platform plugin "windows" #2" for more information.
This code snippet is from the link:
import os
import PySide2
dirname = os.path.dirname(PySide2.__file__)
plugin_path = os.path.join(dirname, 'plugins', 'platforms')
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path
from PySide2.QtWidgets import *
'''
Your code goes here
'''
This solution works for PyQt5 and PySide2 modules.
I don't know if it's relevant but I added the QT_PLUGIN_PATH environment variable in the system before.
That solution enabled me to test PySide2 scripts in IDLE.
However, I faced the same error when I tried to run a bundled script (exe).
With some shallow debugging, it's evident that plugin folder itself is missing. I fixed the problem by adding the plugin folder in the appropriate location:
C:\Users\xxxx\.spyder-py3\My_QtProjects\Project 1\dist\MyQt_1\PySide2\
If the Pycharm console or debugger are showing "Could not find or load the Qt platform plugin windows", the Python EXE file may be located at a different location for the PyCharm interpreter. You might manually select it in File -> Settings -> Interpreter.
Set the working directory: File -> Settings -> Build, Execution, Deployment -> Console -> Python Console -> Working directory. Set it to the parent directory where your all code exists.
Open Control Panel -> System Settings -> Advanced System Settings -> Environment Variables -> New. Set the variable name QT_PLUGIN_PATH , Variable Directory: Users\<Username>\Appdata\Local\Continuum\Anaconda2\Library\plugins.
Restart Pycharm.
I solved it by:
Adding a path:
\Anaconda3\Lib\site-packages\PyQt5\Qt\bin to PATH.
Setting an environment variable:
QT_PLUGIN_PATH as \Anaconda3\Lib\site-packages\PyQt5\Qt\plugins or \Anaconda3\Library\plugins.
Also, you can try:
pyqt = os.path.dirname(PyQt5.__file__)
os.environ['QT_PLUGIN_PATH'] = os.path.join(pyqt, "Qt/plugins")
First, use the command:
conda remove pyqt qt qtpy
Then install using:
conda install pyqt qt qtpy
This worked for me.
Copy the folder
\Anaconda3\Library\plugins\platforms
to
\$\
where $ is your project interpreter folder. For example:
"\project\anaconda_env\Scripts\"
because PyCharm calls the python.exe in this folder, not the one in \Anaconda3.
SOLUTION FOR WINDOWS USERS
Create new environment variable with:
name: QT_PLUGIN_PATH
path: C:\yourpythonpath\Lib\site-packages\PyQt5\Qt\plugins
after that exe file will work
On Windows:
Copy the folder platforms:
C:\Users\%USERNAME%\AppData\Roaming\pyinstaller\bincache00_py35_64bit\pyqt5\qt\plugins\platforms
Paste the folder platform into the folder location of the file .exe:
Example:
c:\MyFolder\yourFile.exe
c:\MyFolder\platforms
You may need to copy the "plugins" file in Anaconda3\Library. For example, on my computer it is
S:\Anaconda3\Library\plugins
to the same path of your .exe file.
copy the plugins from PySide2 and paste and overwrite the existing plugins in Miniconda worked for me.
(base) C:\ProgramData\Miniconda3\Lib\site-packages\PySide2\plugins\platforms>copy *.dll C:\ProgramData\Miniconda3\Library\plugins\platforms\
I had the same problem with Anaconda. For me, although not very elegant, the fastest solution was to unistall and reinstall Ananconda completely. After that, everything worked well again.
I have the same issue and fixed in this way
In Anaconda installation folder I went to : (change it to your installed path):
C:\ProgramData\Anaconda3\Lib\site-packages\PySide2
Edit this file by adding the following code lines :
# below the line 23 type.__signature__
pyside_package_dir = os.path.abspath(os.path.dirname(__file__))
dirname = os.path.dirname(__file__)
plugin_path = os.path.join(dirname, 'plugins', 'platforms')
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path
save this file and try again and the issue should be gone :)
I had the same issue. Following "Activating an environment" in "Managing environments" solved the issue.
In the command line:
conda activate myenv
where myenv=base for my setup.
Please try this in the script
qt_path= os.path.dirname(PyQt5.__file__)
os.environ['QT_PLUGIN_PATH'] = os.path.join(qt_path, "Qt/plugins")
I know everyone above had provided various ways to fix OP's issue. I just want to add on some suggestions.
By adding the QT_PLUGIN_PATH = C:\Users{YOUR_USERNAME}\Anaconda3\Library\plugins as your local machine environment variable it helps to fix OP's PyCharm issue above. However, this will break other systems in your machine like: Dropbox reports missing QT, AMD settings fails to launch(which happens on my side) etc.
Instead of adding QT_PLUGIN_PATH to your machine locally, one can add the environment variable in PyCharm's python interpreter setting as shown below:
This method not only allow your PyCharm's python.exe able to search those DLLs but also not breaking other systems' QT lookup PATH.
Thanks
I installed a package that had a QT-gui that I didn't need.
So I just removed all the Qt modules from my environment.
pip freeze | grep -i qt
PyQt5==5.15.4
PyQt5-Qt5==5.15.2
PyQt5-sip==12.9.0
QtPy==1.9.0
pip uninstall PyQt5
pip uninstall PyQt5-Qt5
pip uninstall PyQt5-sip
pip uninstall QtPy
Problem solved.
if you are using anaconda/miniconda with matplotlib installed.
you'll have to install uninstall anaconda/miniconda and use miniconda without matplotlib, a fix is to use normal python not anaconda.
it has be a know issue here enter link description here
Inspired by Osama Adly, I think this kind of problems are all caused by Anaconda configuration for Qt DLLs on Windows platform.
Just try to install PyQt/PySide in an empty environment besides Anaconda, for example a standalone Python program. You will find that the plugins about platforms are in the site-package directory itself.
For comparation:
\site-packages\PyQt6\Qt6\plugins\platforms
\site-packages\PySide6\plugins\platforms
But it seems that Anaconda contains some software depending on PyQt5 or Qt. Anaconda moves the platforms directory from PyQt5 to another folder and this folder might be contained in the PATH variable when using Anaconda.
\Anaconda3\Library\plugins\platforms
This could lead to unneccessary problems. These DLLs reserve the same name across different generation of Qt. For example, when I tried PySide6 in a virtual environment created with Anaconda, its call for DLLs will mistakenly use the Qt5 DLLS rather than the DLLs in its folder.
In my situation, I did everything listed above and on other forum post:
Copying and pasting files
Adding system variables
Uninstalling, downloading, and reinstalling programs
Restarting the computer
Enabling debugging mode
Running the source code instead of the compiled program
Running sfc /scannow
All of this did not work.
In my case, the solution was to update Windows.
The computer was apparently running a very outdated version of Windows (10?)
After 2-3 hours of installing the update, problem solved.
Source/Inspiration: https://www.partitionwizard.com/clone-disk/no-qt-platform-plugin-could-be-initialized.html
In my case, I had multiple combined problems in order to make PyQt5 run on Windows, see DLL load failed when importing PyQt5
I had the same issue with Qt 5.9 example btscanner.exe. What works in my case is:
Create a folder where is btscanner.exe ( my is c:\temp\BlueTouth )
Run from command prompt windeployqt.exe as follow:
c:\qt\qt5.9.0\msvc2015\bin\windeployqt c:\temp\BlueTouth
/* windeplyqt is the standard Qt tool to packet your application with any needed
libraries or extra files and ready to deploy on other machine */
Result should be something like that:
C:\temp\BlueTouth\btscanner.exe 32 bit, release executable
Adding Qt5Svg for qsvgicon.dll
Skipping plugin qtvirtualkeyboardplugin.dll due to disabled dependencies.
Direct dependencies: Qt5Bluetooth Qt5Core Qt5Gui Qt5Widgets
All dependencies : Qt5Bluetooth Qt5Core Qt5Gui Qt5Widgets
To be deployed : Qt5Bluetooth Qt5Core Qt5Gui Qt5Svg Qt5Widgets
Warning: Cannot find Visual Studio installation directory, VCINSTALLDIR is not set.
Updating Qt5Bluetooth.dll.
Updating Qt5Core.dll.
Updating Qt5Gui.dll.
Updating Qt5Svg.dll.
Updating Qt5Widgets.dll.
Updating libGLESV2.dll.
Updating libEGL.dll.
Updating D3Dcompiler_47.dll.
Updating opengl32sw.dll.
Patching Qt5Core.dll...
Creating directory C:/temp/BlueTouth/iconengines.
Updating qsvgicon.dll.
Creating directory C:/temp/BlueTouth/imageformats.
Updating qgif.dll.
Updating qicns.dll.
Updating qico.dll.
Updating qjpeg.dll.
Updating qsvg.dll.
Updating qtga.dll.
Updating qtiff.dll.
Updating qwbmp.dll.
Updating qwebp.dll.
Creating directory C:/temp/BlueTouth/platforms.
Updating qwindows.dll.
Creating C:\temp\BlueTouth\translations...
Creating qt_bg.qm...
Creating qt_ca.qm...
Creating qt_cs.qm...
Creating qt_da.qm...
Creating qt_de.qm...
Creating qt_en.qm...
Creating qt_es.qm...
Creating qt_fi.qm...
Creating qt_fr.qm...
Creating qt_gd.qm...
Creating qt_he.qm...
Creating qt_hu.qm...
Creating qt_it.qm...
Creating qt_ja.qm...
Creating qt_ko.qm...
Creating qt_lv.qm...
Creating qt_pl.qm...
Creating qt_ru.qm...
Creating qt_sk.qm...
Creating qt_uk.qm...
If you take e look at c:\temp\BlueTouth folder will see
the folders iconengines, imageformats, platforms, translations,
and files D3Dcompiler_47.dll, libEGL.dll, libGLESV2.dll, opengl32sw.dll,
Qt5Bluetouth.dll, Qt5Core.dll, Qt5Gui.dll, Qt5Svg.dll, Qt5Widgets.dll.
These are all of the files and folders need to run btscanner.exe on
this or another machine. Just copy whole folder on other machine and
run the file.
copy platforms from Anaconda3\Library\plugins and put it in the Anaconda3.
for env put the platforms in the specific env\ folder

Cannot import PyQt4.QtGui

I have a working Python 2.6 install and just installed the PyQt4 built for Python 2.6 (available at http://www.riverbankcomputing.co.uk/software/pyqt/download). When I try to import PyQt4.QtGui I get the following error:
ImportError: DLL load failed: The specified procedure could not be found.
I'm on Windows 2k8 64-bit, but my Python install is 32-bit.
Add the the PyQt4 directory containing Qt's applications and DLLs to your PATH environment variable. In PowerShell, provided you didn't change any of your install paths, that'd be
$env:path += ';C:\Python26\Lib\site-packages\PyQt4\bin'
I found a solution on another forum that worked for me. I needed to copy QtGui4.dll and QtCore4.dll into the ...\Python2.7.1\Lib\site-packages\PyQt4 directory. Note, I left the original in the bin directory.
I had installed PyQt4 from a .whl file (from the unofficial windows binaries) and got the same error.
I did what the answers suggested: checked that I installed the correct version, put my PyQt4 directory in the PATH environment variable and had QtCore4.dll and QtGui4.dll, however none of these worked.
The answer was to try and open the designer.exe program: it also had an error, but this time specified which DLL file was missing (it said msvcp140.dll is missing from your computer)
I then downloaded it off dll-files.com and put it in the PyQt4 folder (C:\Python35\Lib\site-packages\PyQt4) and it worked.
I hope this helps !
Are you sure you installed Python x64 ? By default, the Python website makes you download the x32 version, you need to go to this page to download the x64 version and then it will work. I had the same issue and it was fixed this way.
https://www.python.org/downloads/windows/
Hope that will help someone.
Cheers,
Chris
If this does not works, try search for QtCore4.dll, QtGui4.dll, etc. in your paths set in PATH environment variable. In my case I found some qt dll in c:\windows\system32, caused the same error message. I've deleted the dll files, and problem solved. 'C:\Python26\Lib\site-packages\PyQt4\bin' was in my path, but that was not enough.
Neither of the these solutions worked for me. I had Python 3.1 x64 with PyQt 4.8.2-1 x64 on my Windows 7 x64, but uninstalling them and installing the x86 versions of Python 3.1 and PyQt solved the problem for me.
Download the program from http://www.dependencywalker.com to see if there was missing dll.
You need to point the program to the QtGui.pyd file from PyQt.
My case was using MSYS2's mingw-w64-x86_64-python3-pyqt4, it needed libpython3.5m.dll while pacman was already at python3.6
I usage Linux ubuntu 14.04,firstly, Cannot import PyQt4.QtGui because access module PyQt4 not Available in group permission..
if call interpreter:shell>> python not available module QtGui, but if i call interpreter sudo python available QtGui.So, I solved this error , Change permisions folder package PyQt4 in my virtualenv,from property folder,change Owner and Group.
Its works for me :)
None of these solutions worked for me with 64bit Python 3.5. I ended up rolling back Anaconda to 4.1.1 (4.2.0 uses a Qt5 by default, which may or may not be the problem). I also had to install pyqt from a python 3.5 whl - http://www.lfd.uci.edu/%7Egohlke/pythonlibs/#pyqt4.
The binary file on the Riverbank website did not work for me, possibly it only works on Python 3.4?
I have installed pyqt with Anaconda several times, and I believe if it is done correctly the PATH does not need modification (it happens as part of installation) and DLLs do not need to be copied.
Did you verify that PyQt4 is for 32 or 64 bits?, I had the same problem I was using python 2.7.13 32 bit in Windows 10 and PyQt4 4.11 64 Bit, and changed PyQt4 for a 32 bit and it work immediately.

Categories