Can't find exe files using cx_freeze - python

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

Related

Unable to compile with cx_freeze and PySide2

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

cx_Freeze: cannot input ExcelFormulaParser

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")])

cx_Freeze: Python error in main script. Python 3.6 + cx_Freeze

I have problems with compilation python 3.6 to exe using cx_Freeze-5.0.1-cp36-cp36m-win32.whl, help me please.
I have installed Cx-freeze from http://www.lfd.uci.edu/~gohlke/pythonlibs/#cx_freeze
Then i started cmd and run this command:
python setup.py build
setup.py file is below:
import sys
from cx_Freeze import setup, Executable
setup(
name = "Check Telemetry",
version = "0.1",
description = "Check Telemetry",
executables = [Executable("excel_to_sqlite_xlrd-light.py", base = "console")])
Then i have something like this:
But if i run my .exe file i have problem below:
Screenshots with lines that have mistakes below:
Have you got any ideas?
Thank you!
seems that the program doesn't find the dependencies so add this (you have to add the missing dependencies (in this example i put os):
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}
and then:
setup( name = "Check Telemetry",
version = "0.1",
description = "Check Telemetry",
options = {"build_exe": build_exe_options},
executables = [Executable("excel_to_sqlite_xlrd-light.py", base = "console")])

Python3 cx_Freeze error 'no module named gi'

I am trying to use cx_Freeze with a python3 programme I have written which uses Gtk. I ran cxfreeze-quickstart and then python setup.py build using the setup.py file created for me. However, I got this error: ImportError: No module named 'gi'.
This is my setup.py file:
from cx_Freeze import setup, Executable
buildOptions = dict(packages = [], excludes = [])
import sys
base = 'Win32GUI' if sys.platform=='win32' else None
executables = [
Executable('bio_gtk_programme.py', base=base)
]
setup(name='Bio Programme',
version = '1.0',
description = 'Bio Gtk',
options = dict(build_exe = buildOptions),
executables = executables)
Do I need to include 'gi' in packages = [] or add anything to the hooks.py file?
I've also tried this with py2exe on Windows, and I get the same ImportError...

What is my next step using cx_Freeze?

Ok so I have python 3.2 installed and I have cx_Freexe 4.2.3 installed.
I have a folder called Python stuff. In this folder there are 2 files.
setup.py and holg.py (my application)
Here is my setup.py:
import sys
from cx_Freeze import setup, Executable
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "holgame",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("holg.py", base=base)])
The next step I have been doing is Run > cmd:
python setup.py build
what I get is:
'python' is not recognized as an internal or external command, operable program or batch file.
I am only a beginner so I need clear steps. Maybe my programs should be in a different folder or something, I can't really be sure. Does anyone know what the problem is? Thanks
You either need to put Python on the Windows path, or you need to use an explicit path to python. Try:
$ \Python32\Python setup.py build
Here are some good instructions for getting Python installed on your Windows machine: https://openhatch.org/wiki/Boston_Python_Workshop_5/Friday/Windows_set_up_Python
You will first need to cd to the directory containing your code and setup.py. You should find a Windows command prompt tutorial to help with some of this basic stuff.

Categories