So I am trying to compile my code into an .exe using cx_freeze.
Here is the code I am using to compile it...
from cx_Freeze import setup, Executable
import sys
import numpy.core._methods
import numpy.lib.format
from xlwt import ExcelFormulaParser
additional_mods = ['numpy.core._methods', 'numpy.lib.format']
setup(name='ReconApp',
version='0.1',
description='xyz.script',
options = {'build_exe': {'includes': additional_mods}},
executables = [Executable("reconciliation_application.py")])
The code compiles enter image description herewith no errors.
When I go to run the .exe the program launches and closes with this error.
I notice that it does not like something inside xlwt module ExcelFormulaParser
By I do not know what the error is.
any suggestions?
Try to add xlwt library to setup options, i.e.
import sys, os
from cx_Freeze import setup, Executable
build_exe_options = {"packages": ["numpy", "matplotlib", "xlwt"]}
setup(
name = "App",
version = "1.0",
description = "App ...",
options = {"build_exe": build_exe_options},
executables = [Executable("App.py", base = "Win32GUI")])
Related
I have a python program I'm trying to compile with cx_freeze. The GUI I'm using is PySide2.
I've tried including PySide2, here is excluding it, but I keep getting the same error. Below is my setup.py code
from cx_Freeze import setup, Executable
import sys
includefiles = ['README.md', 'debug.log','tcl86t.dll', 'tk86t.dll', 'field.jpg', 'inputClass.py', 'mainfile.qml', 'MyTabView.qml', 'PlayerSelection.qml', 'selectedPlayers.py', 'Settings.qml', 'SimOutput.qml', 'simulationOutput.py']
includes = ["idna.idnadata", "atexit"]
excludes = ["PySide2"]
import os
os.environ['TCL_LIBRARY'] = r'C:\Users\pimat\AppData\Local\Programs\Python\Python36\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\pimat\AppData\Local\Programs\Python\Python36\tcl\tk8.6'
setup(name = "Simulation",
version = "0.2",
description = "Optimization Simulator",
options = {'build_exe':{'includes':includes,'excludes':excludes,'include_files':includefiles}},
executables = [Executable("main.py")])
The program compiles fine, but when running the exe, I get the following error:
"ModuleNotFoundError: No module named 'PySide2'"
So the error was that I had installed cx_freeze with python 3.6, but all of my packages were in a python 3.7 folder. I simply copied and pasted into the 3.6 folder and changed the code a bit, and the exe works great.
from cx_Freeze import setup, Executable
import sys
# dependencies
build_exe_options = {
"packages": ["os", "sys", "re", "idna.idnadata", "atexit", "PySide2.QtCore", "PySide2.QtWidgets", "PySide2.QtUiTools", "PySide2.QtQuick", "PySide2.QtQml", "PySide2.QtGui", "shiboken2"],
"include_files": ['README.md', 'debug.log','tcl86t.dll', 'tk86t.dll', 'field.jpg', 'inputClass.py', 'mainfile.qml', 'MyTabView.qml', 'PlayerSelection.qml', 'selectedPlayers.py', 'Settings.qml', 'SimOutput.qml', 'simulationOutput.py',
],
"excludes": ["Tkinter", "Tkconstants", "tcl", ],
"build_exe": "build",
#"icon": "./example/Resources/Icons/monitor.ico"
}
executable = [
Executable("main.py",
base="Win32GUI",
targetName="Simulation.exe"
)
]
setup(name = "Simulation",
version = "0.2",
description = "Simulator",
options={"build_exe": build_exe_options},
executables=executable
)
T'was a dumb mistake, but I've made worse
I'm compiling a suite of python scripts into executables. I'm using cx_Freeze in order to do so.
The rather common problem is that the lib folder becomes very large. I have excluded modules as much as possible to reduce the size of this but it is still quite sizeable.
Since I am compiling multiple executables, is it possible to have a single shared lib folder that gets referenced by them all to reduce disk size?
An example setup.py is as follows:
import sys, os
from cx_Freeze import setup, Executable
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
executables = [
Executable('MYSCRIPT.py', base=base)
]
additional_mods = ["numpy.core._methods", "numpy.lib.format"]
exclude_mods = ["babel", "scipy", "PyQt5", "tornado", "zmq", "sphinx", "sphinx_rtd_theme", "psutil", "notebook", "nbconvert", "lxml", "cryptography", "bottleneck", "matplotlib"]
build_exe_options = {"excludes": exclude_mods, "includes": additional_mods, "optimize": 1}
os.environ['TCL_LIBRARY'] = r'C:\ProgramData\Anaconda3\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\ProgramData\Anaconda3\tcl\tk8.6'
setup(name='MYSCRIPT',
version='0.1',
includes = ['os'],
options = {"build_exe": build_exe_options},
description='MYSCRIPT',
executables=executables
)
Yes it is possible. The trick is to use a single setup.py where the multiple scripts are added to the executables list.
Take for example the following pair of console-based scripts which both use numpy:
main1.py:
import numpy
print('Program 1, numpy version %s' % numpy.__version__)
input('Press ENTER to quit')
main2.py:
import numpy
print('Program 2, numpy version %s' % numpy.__version__)
input('Press ENTER to quit')
You can freeze this scripts at once with cx_Freeze using the following setup.py:
from cx_Freeze import setup, Executable
base = None
executables = [Executable('main1.py', base=base),
Executable('main2.py', base=base)]
additional_mods = ["numpy.core._methods", "numpy.lib.format"]
build_exe_options = {"includes": additional_mods}
setup(name='MYSCRIPTS',
version='0.1',
options={"build_exe": build_exe_options},
description='MYSCRIPTS',
executables=executables)
You get then two executables main1.exe and main2.exe sharing the same lib folder containing numpy.
i am trying to convert my python script to a exe file
that anyone can run it from any computer, including computers with no python.
so i see some guides that explain the best way is to use in the cx_freeze library.
so i built a small gui application that use in tkinter only, this is my code:
import tkinter
top = tkinter.Tk()
# Code to add widgets will go here...
top.mainloop()
and this is my setup file:
from cx_Freeze import setup, Executable
setup(
name="GUI PROGRAM",
version="0.1",
description="MyEXE",
executables=[Executable("try.py", base="Win32GUI")],
)
and i run this command:
python setup.py build
and then i get this error:
KeyError: 'TCL_LIBRARY
and it only happens when i use tkinter. so i guess i miss something and i need to add in some way the tkinter to the setup file.
can someone help me?
thanks lot you guys.
Try you altering your setup script to this:
from cx_Freeze import setup, Executable
import os
import sys
import os.path
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR,'tcl','tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
files = {"include_files": ["<Path to Python>/Python36-32/DLLs/tcl86t.dll", "<Path To Python>/Python36-32/DLLs/tk86t.dll"], "packages": ["tkinter"]}
setup(
name="GUI PROGRAM",
version="0.1",
description="MyEXE",
options = {"build_exe": files},
executables=[Executable("try.py", base="Win32GUI")],
)
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR,'tcl','tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6') will remove the error message, while files = {"include_files": ["<Path to Python>/Python36-32/DLLs/tcl86t.dll", "<Path To Python>/Python36-32/DLLs/tk86t.dll"], "packages": ["tkinter"]} will include the missing Tk and Tcl runtimes.
I'm new to Python and I'm running Python 3.6. Trying to build an executable using cx_freeze and the code below in a file named "setup.py". I put the python script for the program and the icon file in the python main directory folder. When I type "python setup.py build" into the command prompt it says "running build" and then immediately generates a new command prompt. No errors are given but afterward I can't find the exe anywhere. What am I doing wrong? Am I searching for the exe files in the wrong place or is the build failing without giving an error message?
import cx_Freezefrom cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = ["numpy","tkinter"], excludes = [],includes = ["numpy","tkinter"],
include_files = ["battleship.ico"])
import sys
base = 'Win32GUI' if sys.platform=='win32' else None
executables = [
Executable('battleship.py', base=base)
]
setup(
name='Battleship',
version = '1.0',
description = 'A PvC Battleship Game',
options = dict(build_exe = buildOptions),
executables = executables
)
when you use py2exe
try this
import sys
try:
import py2exe
except:
raw_input('Please install py2exe first...')
sys.exit(-1)
from distutils.core import setup
import shutil
sys.argv.append('py2exe')
setup(
options={
'py2exe': {'bundle_files': 1, 'compressed': True }
},
console=[
{'script': "script.py"}
],
zipfile=None,
)
Note : remplace "script.py" with your python script and run this script like this
python exe.py
I want to create a cx_freeze executable from my windows application that use "pyautoit" module.
pip install -U pyautoit
This is my example code:
main.py
import autoit
autoit.run("notepad.exe")
autoit.win_wait_active("[CLASS:Notepad]", 3)
autoit.control_send("[CLASS:Notepad]", "Edit1", "hello world{!}")
autoit.win_close("[CLASS:Notepad]")
autoit.control_click("[Class:#32770]", "Button2")
setup.py
import sys
from cx_Freeze import setup, Executable
build_exe_options = {
"packages": ["autoit"],
"excludes": []
}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(
name = "AutoItSample",
version = "0.1",
description = "Automate Notepad Editor",
options = {"build_exe": build_exe_options},
executables = [Executable("main.py", base=base)],
)
And I created the build with this command inside my project folder.
python setup.py build
This module use a .dll file included inside the module folder.
autoit
lib
AutoItX3.dll
autoit.py
...
But cx_freeze doesn't include this .dll in the library.zip archive.
I tried to include the lib folder manually inside the library.zip archive.
But I've got the same error.
http://pix.toile-libre.org/upload/original/1428496271.png
What should I do to make it work?
Try using the zip_includes option in your setup.py file:
import sys
from cx_Freeze import setup, Executable
build_exe_options = {
"packages": ["autoit"],
"excludes": [],
"zip_includes": ['AutoITX3.dll']
}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(
name = "AutoItSample",
version = "0.1",
description = "Automate Notepad Editor",
options = {"build_exe": build_exe_options},
executables = [Executable("main.py", base=base)],
)