Make a python program with PySide an executable - python

I have a python program:
import sys
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtWebKit import *
app = QApplication(sys.argv)
web = QWebView()
web.load(QUrl("htpp://www.google.com"))
web.show()
web.resize(650, 750)
web.setWindowTitle('Website')
sys.exit(app.exec_())
I used google.com just for example. But if i want to make an executable of this program with py2exe but it wont work. I get this error:
With other programs without PySide it does work. But with PySide it doesnt. How can I make it work?

You need Microsoft Visual C runtime.
You should take a look at this: http://qt-project.org/wiki/Packaging_PySide_applications_on_Windows . In the py2exe tutorial it explains about the runtime you should install.

You are missing a DLL. The DLL in question can be (at least formerly) obtained from Microsoft by downloading their free compiler package.
Alternatively, ensure that this process has the right paths set to find the DLL in question.

Related

Can't seem to get a window from PYQT5 in Pycharm (macOS Big Sur)

I am using macOS Big Sur beta currently. I have been able to download the libraries via Pycharm 2020.1.2 however, when running my program, no window appears to show what I've been working on.
Example:
Here is a simple line of code I've gotten as an example.
import sys
from PyQt5.QtWidgets import QApplication, QLabel
app = QApplication([])
label = QLabel('Welcome to PYQT5 Tester')
label.show()
app.exec_()
When I run the app, there are no errors and the sole description is my file directory. I am really confused to if I haven't installed anything but any help would be appreciated.
Went down to PyQt5==5.13 and it's working for me now.

'PyQt4 module not found' - Cannot use PyQt to open a GUI

I am very new to using PyQt4. So far, i have used QtDesigner to create the GUI windows i shall be using for my program.
However, when i run the first bit of python coding to get the user interface to appear, i get an error i cannot find a solution to.
Here's the code:
import sys, os
from PyQt4 import QtCore, QtGui, uic
form_class = uic.loadUiType("HomeScreen.ui") [0]
All i am trying to do with this is to load a GUI, which is called 'HomeScreen.ui'.
Upon running this code, the python shell returns an error saying:
from PyQt4 import QtCore, QtGui, uic
ImportError: No module named 'PyQt4'
I have Python 3.5 installed, as well as PyQt v4.11.4 and PyQt5.6.
'QtGui' and 'QtCore' are both saved in a folder called PyQt4 (and PyQt5), which are both stored in the path:
C:\Program Files (x86)\Python\Python35-32\Lib\site-packages
I believe this is where third party modules are supposed to be stored, but python can never find the module and i repeatedly get the same error message.
Any help would be appreciated.
I also work in windows and python 3,just run the execute file to install pyqt:
https://sourceforge.net/projects/pyqt/files/PyQt5/PyQt-5.6/
it works well in my environment

importing local installation of PySide into Python

Have been searching for this for a while and trying different solutions, but nothing seems to fix my problem.
I am sitting on a unix server, and have installed PySide locally in my home directory, so python will not pick it up. (not added to PYTHONPATH?).
I am not able to import PySide in my python script.
Trying the following:
import sys
sys.path.append('~/PySide-1.2.4/pyside_build/py2.7-qt4.8.5-64bit-release/pyside/PySide/')
from PySide.QtCore import *
from PySide.QtGui import *
Not sure if I am appending the correct path. At least there is a init.py file there and QtCore.so, and other *.so files.
Is it still correct to import from PySide?

No module named when using PyInstaller

I try to compile a Python project under Windows 7 using PyInstaller. The project works fine, there are no issues, however when I try to compile it the result doesn't work. Though I get no warnings during compilation there are many in the warnmain.txt file in the build directory: warnmain.txt
I don't really understand those warnings, for example "no module named numpy.pi" since numpy.pi is no module but a number. I never tried to import numpy.pi. I did import numpy and matplotlib explicitly. In addition I'm using PyQt4. I thought the error might be related to those libraries.
However I was able to compile a simple script which uses numpy succesfully:
import sys
from PyQt4 import QtGui, QtCore
import numpy as np
class MainWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.pb = QtGui.QPushButton(str(np.pi), self)
app = QtGui.QApplication(sys.argv)
main = MainWindow()
main.show()
sys.exit(app.exec_())
Successfully here means that the created executable file actually showed the desired output. However there is also a warnmain.txt file created which contains exactly the same 'warnings' as the one before. So I guess the fact that compiling my actual project does not give any success is not (or at least not only) related to those warnings. But what else could be the error then? The only output during compilation are 'INFO's and none of the is a negative statement.
I did not specify an additional hook directory but the hooks where down using the default directory as far as I could read from the compile output, e.g. hook-matplotlib was executed. I could not see any hook for numpy neither could I for my small example script but this one worked. I used the following imports in my files (not all in the same but in different ones):
import numpy as np
import matplotlib.pyplot as ppl
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
from PyQt4 import QtGui, QtCore
import json
import sys
import numpy # added this one later
import matplotlib # added this one later
Since PyInstaller does not give any errors/warnings I could not figure out if the problem is related to the libraries or if there is something else to be considered.
Had a similar problem with no module named FileDialog. Discovered that with version 3.2, I could use
pyinstaller --hidden-import FileDialog ...
instead of modifying my main script.
See Listing Hidden Imports documentation
Pyinstaller won't see second level imports. So if you import module A, pyinstaller sees this. But any additional module that is imported in A will not be seen.
There is no need to change anything in your python scripts. You can directly add the missing imports to the spec file.
Just change the following line:
hiddenimports=[],
to
hiddenimports=["Tkinter", "FileDialog"],
If you are getting ModuleNotFoundError: No module named ... errors and you:
call PyInstaller from a directory other than your main script's directory
use relative imports in your script
then your executable can have trouble finding the relative imports.
This can be fixed by:
calling PyInstaller from the same directory as your main script
OR removing any __init__.py files (empty __init__.py files are not required in Python 3.3+)
OR using PyInstaller's paths flag to specify a path to search for imports. E.g. if you are calling PyInstaller from a parent folder to your main script, and your script lives in subfolder, then call PyInstaller as such:
pyinstaller --paths=subfolder subfolder/script.py.
The problem were some runtime dependencies of matplotlib. So the compiling was fine while running the program threw some errors. Because the terminal closed itself immediately I didn't realize that. After redirecting stdout and stderr to a file I could see that I missed the libraries Tkinter and FileDialog. Adding two imports at the top of the main solved this problem.
I was facing the same problem and the following solution worked for me:
I first removed the virtual environment in which I was working.
Reinstalled all the modules using pip (note: this time I did not create any virtual environment).
Then I called the pyinstaller.
The .exe file created thereafter executed smoothly, without any module import error.
I had the same problem with pyinstaller 3.0 and weblib. Importing it in the main didn't help.
Upgrading to 3.1 and deleting all build files helped.
pip install --upgrade pyinstaller
If the matter is that you don't need Tkinter and friends because you are using PyQt4, then it might be best to avoid loading Tkinter etc altogether. Look into /etc/matplotlibrc and change the defaults to PyQt4, see the 'modified' lines below:
#### CONFIGURATION BEGINS HERE
# The default backend; one of GTK GTKAgg GTKCairo GTK3Agg GTK3Cairo
# CocoaAgg MacOSX Qt4Agg Qt5Agg TkAgg WX WXAgg Agg Cairo GDK PS PDF SVG
# Template.
# You can also deploy your own backend outside of matplotlib by
# referring to the module name (which must be in the PYTHONPATH) as
# 'module://my_backend'.
#modified
#backend : TkAgg
backend : Qt4Agg
# If you are using the Qt4Agg backend, you can choose here
# to use the PyQt4 bindings or the newer PySide bindings to
# the underlying Qt4 toolkit.
#modified
#backend.qt4 : PyQt4 # PyQt4 | PySide
backend.qt4 : PyQt4 # PyQt4 | PySide
May not be a good practice but installing pyinstaller in the original environment used in my project (instead of a separate venv) helped resolve ModuleNotFoundError
I had similar problem with PySimpleGUI.
The problem was, pyinstaller was installed in different directory.
SOLUTION (solved for me) : just install pyinstaller in the same directory in which the file is present (that to be converted to exe)
If these solutions don't work, simply deleting and reinstalling pyinstaller can fix this for you (as it did for me just now).
Putting this here for anyone else who might come across this post.
I had the same error. Mine said "ModuleNotFoundError: No module named 'numpy'". I fixed it by typing the following in the cmd:
pip install pyinstaller numpy

Error loading Qt libraries with Wing and PyQt

I've been trying to get PyQt4 to work on my OSx machine (10.8.5) for some time - I've loaded it on my windows machine with no problem by using an installer.
I have sip 4.8.5, Python 2.7 Qt 4.8.5 loaded on my machine using homebrew.
When I try to debug the following file in WING, I get the following error:
Code from Zetcode as a test
import sys
import QtGui
def main():
app = QtGui.QApplication(sys.argv)
w = QtGui.QWidget()
w.resize(250, 150)
w.move(300, 300)
w.setWindowTitle('Simple')
w.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
Exception:
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/PyQt4/_qt.so, 2):
Library not loaded: QtDesigner.framework/Versions/4/QtDesigner
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/PyQt4/_qt.so
Reason: image not found
Why is the Qt library not loading? What do I need to do to get the library to load?
Thanks,
-j
I don't personally use homebrew, but I'm pretty sure it installs stuff in /usr/local. From the error message it looks like it is accessing /Library/Frameworks/Python.framework. I also don't use WingIDE, but it looks like it is using a different python install than you want it to. I'm sure there is a way to specify which python it uses.
You probably need to set the Python Executable in Project Properties (from the Project menu) to /usr/local/bin/python -- or whatever the value of sys.executable is in the Python that has PyQt4 installed into it.
Note that in Wing 101 this is done in the Configure Python dialog instead, which is accessed from the Edit menu.

Categories