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
Related
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?
So i wrote a little programm in python with use of tkinter. The repo is found here: https://github.com/Odatas/MeisterTools
I now want to create an exe so people only need to use the exe when they want to use the program. But the exe i create with pyinstaller doesnt work and throws the error:
Import Error: cannot import name 'travel' from 'main'
The cmd i opend to creat the exe is directly out of anaconda envoirment.
I cd into the folder where all the scripts are and then run it like this:
pyinstaller --onefile patrickstools2.py
I even tried to make every import an hidden import:
pyinstaller --onefile --hidden-import=init --hidden-import=main --hidden-import=checker --hidden-import=contact --hidden-import=dangers --hidden-import=droptable --hidden-import=importexcel --hidden-import=odatasfunctions --hidden-import=randomenpc --hidden-import=scrolltest --hidden-import=sonstiges --hidden-import=travel patrickstools2.py
that doesnt help either. I added the path through Anaconda to the PYTHONPATH variable...so it should be know in any way shape or form.
The complet code is in Anaconda. The Error gets thrown in the import section of the main file:
# page classes import
import os
try:
import Tkinter as tk
except ImportError:
import tkinter as tk
try:
import ttk
py3 = False
except ImportError:
import tkinter.ttk as ttk
py3 = True
# page classes import
from . import travel
from . import contact
from . import dangers
from . import sonstiges
from . import randomenpc
I allready created an exe with pyinstaller from a previous version. But i made some changes to the structure of the programm. The run.py is only there because i work with spyder and as far as i know spyder needs it because else the import doesnt work correctly.
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_())
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?
from PyQt4.QtCore import * works in PyCharm but doesn't work with Python3 and PyQt4 on the Raspberry Pi. I checked under usr/... and QtCore is shown. I figure Raspbian doesn't like the .Qtcore so I've tried to change it to another format from PyQt4 import QtCore Pycharm gives errors that Qt is not defined. The only thing in Pycharm that works is 'from PyQt4.QtCore import *' and I've tried everything I can find. Can anyone tell me why the second part won't work in PyCharm and what the correct format is so it will work under Raspbian?