I`m trying to make an executable from my python script called ProyectoNew.py. It works with a folder called "Imagenes" and another called "ModulosExternos", and a PyQT5's .ui file like this:
Here`s the Code posted in GitHub: https://github.com/TheFlosh/ProyectoSoftware.git
I`ve tried to use Pyinstaller, Py2Exe and CXFreeze but it didn't worked. Using each one of these modules to create a .exe file I've got the same result when I tried to execute it in another PC, as shown here:
On the LEFT of the picture you can see what I get after using pyinstaller (or Py2Exe), on the right you can see what I need to show.
Here are the modules that I use in my code ("ModulosExternos" is the folder where I put some particular modules that my code needs):
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
import pyttsx3
from pyttsx3.drivers import sapi5
import PyQt5
import sip
import os
from ModulosExternos import Boton_1,Boton_2,Boton_3,Boton_4,Boton_Final,Listas_Pictogramas, Frases_Completas
And here is the last part of it, to instantiate the GUI:
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
GUI = ProyectoNew()
GUI.show()
sys.exit(app.exec())
I`ve read a lot of posts on the internet that recommended creating Setup.Py file to initiate the process of creating an executable file of my project. These are some examples of what I did with two of them:
With CX_Freeze:
import sys
import os
from cx_Freeze import setup, Executable
files = ['icono.ico','/Imagenes']
target = Executable(
script = "/ProyectoNew.py",
base = 'Win32GUI',
)
#Setup
setup(
name = "Proyect2",
version = "1.6",
description = "Software",
author = "----",
options = {'build_exe': {'include_files' : files}},
executables = [target]
)
With Py2Exe:
from cx_Freeze import setup, Executable
setup(name = "Proyect2",
version="1.0",
description = "Software",
executables = [Executable("ProyectoNew.py")],)
With Pyinstaller I typed: python --nowindowed --onefile ProyectoNew.py but I constantly got the same result as shown before.
I think that when I execute Pyinstaller, the .exe file doesn`t load the modules and the images that I use. What am I missing while creating the file? What do I need to do to execute the .exe file in another PC?.
I would prefer to use pyinstaller,but using any one of these will help me.
What's is wrong with that? You get some kind of error? Please edit your question with that.
With pyinstaller and this command, you should be able easily build an executable file:
pyinstaller [FILE].py -w -F
This command generate a /dist folder with the neccesary files and .exe file to run
*-w param is for do not provide a console window for standard i/o
*-F param is for one-file bundled executable
You can check more params here
PD: Before, you need obviously install pyinstaller:
pip install pyinstaller
Related
I created a file called dork.py in Python and wrote the following inside the file:
import os,time
print(os.path.basename(__file__))
time.sleep(3)
as a result it prints dork.py on the screen
In the setup.py I created for cx_Freeze, I wrote the following:
from cx_Freeze import setup, Executable
build_exe_options = {
'packages': ['os','time'],
'include_files':['/']
}
setup(
name='YourAppName',
version='1.0',
description='Your App Description',
options={'build_exe': build_exe_options},
executables=[Executable('dork.py')]
)
When I run the exe file I want it to print dork.exe but it says dork.py. I tried this with pyinstaller and pyinstaller was giving an error
How can i solve this
I expected it to print dork.exe but it says dork.py
the __file__ will point to the original python file after freezing, this is the way cx_freeze or pyinstaller "patches" these variables when it freezes the modules.
a simple way to make it return .exe when the app is frozen is outlined in the documentation
import sys
if getattr(sys, "frozen", False):
# The application is frozen
script_path = sys.executable
else:
# The application is not frozen
script_path = __file__
print(script_path)
I've got a command line program that uses Python's click package. I can install and run it locally, no problem with:
pip install --editable . # (or leave out the editable of course)
Now, I'd like to create an executable file that can be distributed and run standalone. Typically, since I'm in a Windows environment, I would use one of py2exe, pyinstaller or cx_Freeze. However, none of these packages work.
More specifically, they all generate an executable, but the executable does nothing. I suspect this problem is because my main.py script doesn't have a main function. Any suggestions would be very helpful, thanks in advance!
Can reproduce the issues with code copied from here.
hello.py
import click
#click.command()
def cli():
click.echo("I AM WORKING")
setup.py
from distutils.core import setup
import py2exe
setup(
name="hello",
version="0.1",
py_modules=['hello'],
install_requires=[
'Click'
],
entry_points="""
[console_scripts]
hello=hello:cli
""",
console=['hello.py']
)
If someone could supply a working setup.py file to create an executable and any other required files, that would be much appreciated.
From the console:
python setup.py py2exe
# A bunch of info, no errors
cd dist
hello.exe
# no output, should output "I AM WORKING"
I much prefer pyinstaller to the other alternatives, so I will cast an answer in terms of pyinstaller.
Starting click app when frozen
You can detect when your program has been frozen with pyinstaller, and then start the click app like:
if getattr(sys, 'frozen', False):
cli(sys.argv[1:])
Building an exe with pyinstaller
This simple test app can be built simply with:
pyinstaller --onefile hello.py
Test Code:
import sys
import click
#click.command()
#click.argument('arg')
def cli(arg):
click.echo("I AM WORKING (%s)" % arg)
if getattr(sys, 'frozen', False):
cli(sys.argv[1:])
Testing:
>dist\test.exe an_arg
I AM WORKING (an_arg)
I'm attempting to package a PyQt application using cx_freeze. I'm running Python 3.4, Qt 5.6, PyQt 5.5.1 and Cx_freeze 4.3.4 on Windows 7.
There are three pieces to my application, the python/PyQt code, a Qt UI file which contains the GUI elements, and a QML file which runs an interactive map similar to the places_map.qml example. The QML file using the osm map plugin.
My Qt UI file includes a QQuickWidget whose source is the QML file. I'm attempting to package the application, so that others can run it without installing python and Qt. I've created a custom setup.py scripts for cx_freeze to use. However, I keep encountering various ImportErrors related to the QQuickWidget when running my built Exe files. The error occurs when my Python code loads the UI file. I've attempted to include pretty much anything related to QQuickWidgets and the QML code that I can think of in my setup.py file. Initially, the ImportError was missing QQuickWidgets. After adding the SIP QQuickWidget files, the error is now related to QQuickWidgets.QQuickWidget. Below is my setup.py file.
from cx_Freeze import setup, Executable
import os
PYQT5_DIR = "c:/Python34/lib/site-packages/PyQt5/"
include_files = ['TTRMS.ui','places_map.qml',
(os.path.join(PYQT5_DIR, "qml", "QtQuick.2"), "QtQuick.2"),
(os.path.join(PYQT5_DIR, "qml", "QtQuick"), "QtQuick"),
(os.path.join(PYQT5_DIR, "qml", "QtQml"), "QtQml"),
(os.path.join(PYQT5_DIR, "qml", "Qt"), "Qt"),
(os.path.join(PYQT5_DIR, "qml", "QtPositioning"), "QtPositioning"),
(os.path.join(PYQT5_DIR, "qml", "QtLocation"), "QtLocation"),'C:/Python34/Lib/site-packages/PyQt5/uic/widget-plugins',
'C:/Python34/Lib/site-packages/PyQt5/plugins/geoservices','C:/Python34/Lib/site-packages/PyQt5/sip/PyQt5/QtQuickWidgets',
'C:/Python34/Lib/site-packages/PyQt5/sip/PyQt5/QtQuick']
buildOptions = dict(packages = ['PyQt5.QtQuickWidgets',"atexit","sip","PyQt5.QtCore","PyQt5.QtGui","PyQt5.QtWidgets",
"PyQt5.QtNetwork","PyQt5.QtOpenGL", "PyQt5.QtQml", "PyQt5.QtQuick"],
excludes = [], includes = ["atexit","re"], include_files = include_files)
import sys
base = 'Win32GUI' if sys.platform=='win32' else None
executables = [
Executable('Main.py', base=base, targetName = 'main.exe')
]
setup(name='TTRMS',
version = '1.0',
description = 'Travel Time Reliability',
options = dict(build_exe = buildOptions),
executables = executables)
Here is the error when running my Exe:
I'm not sure what else I need to include in my setup.py in order to package the application properly. I've successfully packaged a small PyQt app with a UI file, but never a UI file which then imports QML through a QQuickWidget. I'm not very knowledgeable about Qt either, so this whole process is new to me. Please let me know if you have any suggestions and let me know if I need to clarify anything. I appreciate any help!
I created a executable with py2exe for a wxpython app what working fine, when starting the executable created gives me an error about os.popen. code that creates the executable is:
# setup.py
from distutils.core import setup
import py2exe
setup(name="GridSimple",scripts=["GridSimple.py"],)
http://i.stack.imgur.com/u9Sj8.jpg
Here about this problem http://wiki.wxpython.org/CreatingStandaloneExecutables?highlight=%28unicows.dll%29#py2exe
They say "include the file unicows.dll" Where is it?
I coded a python application with a GUI in Tkinter with pictures. Now that I have finished, I am trying to convert it to a .exe with py2exe. All my pictures are in the same folder as my python file and setup file, but when I try to convert my python file via the Command Prompt, I get error messages saying that my .ico file is not defined and that it can not copy it. I think the problem is due to my setup.py file. How do I allow my images to be copied into the new .exe executable file without getting errors I have never used py2exe before.
Setup file:
from distutils.core import setup
import py2exe
setup(console=['Gui.py'])
Error:
How do I fix this?
You may have just forgotten to define your icon:
cfg = {
'py2exe.icon':'icon.ico',
...
}
Try to change your setup.py like this:
from distutils.core import setup
import py2exe
data_files = [('', [r'standardicon.ico'])]
setup(
windows =['Gui.py'],
data_files = data_files
)