Module PyQt5 import issue - python-3.x

I got this error on PyCharm
Traceback (most recent call last)
from import QtCore, QtGui, QtWidgets ModuleNotFoundError: No module named 'PyQt5'
this is the import statement
from PyQt5 import QtCore, QtGui, QtWidgets
Although that I have checked the library in terminal using pip3 command and it works.
Also, I have configured manually the interrupter to be with python3 but still the error not resolved. Any idea of solving this issue?

Related

Python Import Error: No module named 'PyQt4'

I'm trying to run a Python program that tries to import
from PyQt4 import QtGui, QtCore
and gives me an Import Error: No module named 'PyQt4'.
I use a conda environment and made sure: pyqt is installed, version 5.6.0.
If I change the import statement to
from pyqt import QtGui, QtCore
It doesn't work either, it gives me the same import error. At this point I'm totally confused:
Why is it telling me there is no module named pyqt? I know it is there. If I type conda list it shows me that it is installed.
Trying to install PyQt4 via pip or conda fails because apparently there is not package named PyQt4, there is only a package named pyqt. How can this program try to import PyQt4 then?
How can I fix this?
I'm on Ubuntu 16.04 and Python 3.
Try using PyQt5 like below:
from PyQt5 import QtGui, QtCore

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?

ImportError PyQt5 in PyCharm on Linux

I install PyQt5 and PyCharm on Linux (python 3.5.2), but after this easy code:
import sys
from PyQt5 import QtGui
from PyQt5 import QtCore
from PyQt5.QtWebEngineWidgets import QWebEngineView
app = QtGui.QGuiApplication(sys.argv)
window = QWebEngineView()
window.load(QtCore.QUrl("https://google.com"))
window.show()
sys.exit(app.exec_())
I have this Error:
Traceback (most recent call last): File
"/home/user/Browser/BrowserQt5.py", line 4, in
from PyQt5.QtWebEngineWidgets import QWebEngineView
ImportError: libQt5WebEngineWidgets.so.5: cannot open shared object file: No such file or directory
How to fix this Error?

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