Python Import issue With PyQt4.QtCore - pyqt4

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?

Related

Pyinstaller with anaconda in spyder

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.

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?

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