I have found plenty of posts regarding this issue, but no answers that work for me.
PROBLEM:
I am trying to run this code:
from PyQt4 import QtCore, QtGui
I get this error in return:
ImportError: cannot import name QtCore
I append the path to PyQt4 to sys.path (C:\Python27\Lib\site-packages\PyQt4) and importing just PyQt4 throws no errors. I can see that QtCore.pyd and QtGui.pyd are in that directory and the directory has its __init__.py file.
Specs:
Windows 7 x64
python v2.6.8
PyQt v4.10.4
If you're using Python-2.6.x, you will have to use an installer for an earlier version of PyQt4. The most recent version available is for PyQt-4.10/Qt-4.8.4, which can be downloaded from here:
PyQt4-4.10-gpl-Py2.6-Qt4.8.4-x64.exe
PyQt4-4.10-gpl-Py2.6-Qt4.8.4-x32.exe
Related
I am trying to import PyQt5 by :
from PyQt5 import QtCore, QtGui, QtWidgets
But it is giving me the Error : Unable to import PyQt5. PyQt5 is definitely installed in the Virtualenv in the location -
"c:\users\TM\documents\python projects\pyqt test\env\lib\site-packages"
Which I did by - 'py -m pip install pyqt5' while in the (env).
My program is also in the 'pyqt test' folder.
I've installed Python on a new PC and this is the first time I'm having this problem, before I could just import anything in an env without any error.
EDIT: This is my sys.path:
['c:\\Users\\TM\\Documents\\Python Projects\\PyQt Test',
'C:\\Users\\TM\\AppData\\Local\\Programs\\Python\\Python38-32\\python38.zip',
'C:\\Users\\TM\\AppData\\Local\\Programs\\Python\\Python38-32\\DLLs',
'C:\\Users\\TM\\AppData\\Local\\Programs\\Python\\Python38-32\\lib',
'C:\\Users\\TM\\AppData\\Local\\Programs\\Python\\Python38-32',
'C:\\Users\\TM\0\AppData\\Roaming\\Python\\Python38\\site-packages',
'C:\\Users\\TM\\AppData\\Local\\Programs\\Python\\Python38-32\\lib\\site-packages']
I've recently upgraded PyQt5 from 5.5.1 to 5.6.0 using the Windows 32-bit installer here: https://www.riverbankcomputing.com/software/pyqt/download5. I've also upgraded my python from 3.4 to 3.5.
When I run my old code (which used to work) with the latest version I get an exception:
from PyQt5.QtWebKitWidgets import *
ImportError: No module named 'PyQt5.QtWebKitWidgets'
All of my QT calls in my python occur consecutively and are (and I know I shouldn't be importing * but that's beside the issue here I think):
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebKitWidgets import *
So the QtCore, QtGui and QtWidgets imports are all OK.
Also, when I search the source for QtWebKitWidgets there appears several references to this module.
Finally my python path looks like:
C:\PYTHON35;C:\PYTHON35\DLLs;C:\PYTHON35\LIB;C:\PYTHON35\LIB\LIB-TK;
and environment path:
C:\Python35\Lib\site-packages\PyQt5;C:\Python35;C:\Python35\Lib;C:\Python35\Lib\site-packages;C:\Python35\Scripts ....
QtWebKit got deprecated upstream in Qt 5.5 and removed in 5.6.
You may want to switch to PyQt5.QtWebEngineWidgets.QWebEngineView.
For basic use of PyQt5.QtWebKitWidgets.QWebView, it can simply be updated to use PyQt5.QtWebEngineWidgets.QWebEngineView in the source code, but there may be some differences in the new component which require further adjustments.
I was trying to run qutebrowser and it had the same error, the answer is simple, the packages changed.
You have two solutions:
1)
pip install PyQtWebEngine
2)
pip install PyQt5==5.11.3
Hope this helps any future problems
In PyQt5 "QtWebKitWidgets" is Deprecated. I just replace this line
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
from PyQt5.QtWebKit import QWebSettings
With this code:
from PyQt5.QtWebEngineWidgets import QWebEngineView as QWebView,QWebEnginePage as QWebPage
from PyQt5.QtWebEngineWidgets import QWebEngineSettings as QWebSettings
If you really want to use PyQt5.QtWebKitWidgets, you could run this from the command line:
pip install PyQtWebKit
and let it do what it does.
In PyQt5 "QtWebKitWidgets" is no longer available. Instead it is replaced with "QtWebEngineWidgets". So you have to make this change in your code.
For more information: http://doc.qt.io/qt-5/qtwebenginewidgets-qtwebkitportingguide.html
Hi I tried to use a animation script
free meshcache for maya
# this is the error that I have ( No module named PyQt4 # )
Error: line 1: ImportError: file C:/Users/Lav/Documents/maya/2016/scripts/meshCache_script.py line 5: No module named PyQt4 `
#I am using maya 2016 with service pack in window 7 64 bit
Is it possible to change this script, so that everybody can use without dealing with pyqt4 install or others.
If I could use this script, I really appreciate for you.
Thank you guys.
In the specific case of that script it should be as easy as replacing:
from PyQt4 import QtGui, QtCore
import sip
with:
from PySide import QtGui, QtCore
import shiboken
and then, on line 32, replacing:
return sip.wrapinstance(long(controlPoniter), QtCore.QObject)
with:
return shiboken.wrapInstance(long(controlPoniter), QtGui.QWidget)
Then follow the instructions here (where I assume you got the script) and it should work.
What I suggested is what I believe the author was doing with the meshCache_script_2016.py file he mentions, in the page linked above. I downloaded the zipped file from there but couldn't find meshCache_script_2016.py in there, so you might want to ask the author if he omitted it on purpose (in case he realised that other parts of his script and/or plugin would break in Maya 2016, anyway).
I'm trying to run an example script using PyQt 5 that contains the following:
import sys
from PyQt5 import QtCore, QtGui, uic
This throws:
ImportError: cannot import name 'QtCore'
I'm running 64-bit versions of both Python 3.4 and PyQt 5 on 64-bit Windows 10. When I try
from PyQt5 import QtCore
in the terminal it works fine; I only get the import error when running a script. Other similar questions on StackOverflow led me to check sys.path, which produced:
>>> print(sys.path)
['', 'C:\\Windows\\SYSTEM32\\python34.zip', 'C:\\Python34\\DLLs',
'C:\\Python34\\lib', 'C:\\Python34', 'C:\\Python34\\lib\\site-packages',
'C:\\Python34\\lib\\site-packages\\PyQt5']
os.environ['PATH'].split(os.pathsep)
results in a long list of directories, including the location of PyQt5 in the Python34 folder.
I've also tried uninstalling and reinstalling both Python and PyQt, and tried PyQt4 instead of 5, all with no success.
I am trying to build a very basic executable (Windows) using PySide. The following script runs properly in the interpreter (Python 2.7, PySide 1.1.2)
#!/usr/bin/python
import sys
sys.stdout = open("my_stdout.log", "w")
sys.stderr = open("my_stderr.log", "w")
import PySide.QtGui
from PySide.QtGui import QApplication
from PySide.QtGui import QMessageBox
# Create the application object
app = QApplication(sys.argv)
# Create a simple dialog box
msgBox = QMessageBox()
msgBox.setText("Hello World - using PySide version " + PySide.__version__)
msgBox.exec_()
I tried 3 methods (py2exe, pyinstaller and cx_freeze) and all the 3 generated executables fail to execute. The two stdout/stderr files appear, so I found the first PySide import is making everything fail. (Unhandled exception/Access violation)
I analyzed the executable file with depends (http://www.dependencywalker.com/) and everything looks correctly linked.
Any idea?
You need to add the atexit module as an include. source: http://qt-project.org/wiki/Packaging_PySide_applications_on_Windows
(is also the case for Linux btw)
Thank you for your help. Actually, this did not change anything :/ However, I found a solution to my problem: if I add from PySide import QtCore, QtGui, then the executable (with pyinstaller) does work!