What is my next step using cx_Freeze? - python

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.

Related

Cx_freeze bdist_msi directories syntax? how to interpret 'directory_table'

I am having trouble creating new directories with the MSI generated with cx_freeze. I don't understand the windows direcotry_tables object and there is little to no documentation explaining it. has anyone had any success with this?
here is the documentation for the setup script for cx_freeze bdist_msi.
https://cx-freeze.readthedocs.io/en/latest/setup_script.html#commands
similar windows documentation on 'directory tables'
https://learn.microsoft.com/en-us/windows/win32/msi/directory-table?redirectedfrom=MSDN
I would like my installer to create a directory in C:\ProgramData but I can't figure out what arguments to use in the "directory_table" 3 tuple to do this. Below is the default example directory table which works with no errors but I am not sure where the directory is actually put.
directory_table = [
("ProgramMenuFolder", "TARGETDIR", "."),
("MyProgramMenu", "ProgramMenuFolder", "MYPROG~1|My Program"),]
Hopefully someone has run into this previously, thanks for the help.
below is my setup.py:
from cx_Freeze import setup, Executable
import sys
company_name = 'MyCompany'
product_name = 'TestTKApp'
#list of 3-tuples. need help here.
directory_table = [
("ProgramMenuFolder", "TARGETDIR", "."),
("MyProgramMenu", "ProgramMenuFolder", "MYPROG~1|My Program"),]
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
build_exe_options = {"includes": ["testmath"],
"path" : sys.path,
"include_files": [(r"PATH\TO\SOME\FILE","junk.txt")],
}
bdist_msi_options = {
# 'upgrade_code': '{66620F3A-DC3A-11E2-B341-002219E9B01E}',
'add_to_path': False,
'initial_target_dir': r'C:\ProgramFiles\%s\%s' % (company_name, product_name),
'target_name' : 'TestTKapp Installer',
'directories' : directory_table,
"summary_data": {"author": "Me",
"comments": "Test TKapp",}
}
setup(name='Test Dist App',
version = ' 1.0.0',
executables = [Executable(r"C:\PATH\TO\MY\APP\TestTKAPP.py", base = "Win32GUI")],
options={'bdist_msi': bdist_msi_options,
'build_exe': build_exe_options},
)
Ended up using an Inno Script to create my MSI. would still like to know how to do with with cx_freeze.
see documentation for inno scripting here. much easier and simply process for building windows installers:
https://jrsoftware.org/isdl.php
in summary(How to build a python exe);
use pipreqs to create a requirements.txt for my project
build virtual environment with that requirments.txt
create a cx_freeze setup.py script to create MyApp.exe
run cx_freeze setup.py from my virtual environment
use Inno Script to create windows installer (msi) for MyApp.exe

Using cx_Freeze with Graphviz dependency

I have a python program that uses the Graphiz module, the output of the program uses the Graphviz windows installation to create an image.
My program is for average windows users and my goal is to deliver one msi installer.
I don't have issues using the cx_Freeze to pack my python modules and run the outcome afterwards...
The problem is, the program depends on the installed Graphviz dir to create the image from my programs output moreover the dir's bin folder should be in the system path....
If there is a solution using cx_Freeze (and I tried and didn't find one)
pls help me
If not pls advice how can I circumvent this problem
Thanks a million!
import sys, os
from cx_Freeze import setup, Executable
build_exe_options = {"packages": ["PIL.Image",
"tkinter",
"graphviz",
"Rec_FFT",
"graph_visualization",
"math",
"cmath"],
"include_files": [
r"D:\Yigal\Python36-32\DLLs\tcl86t.dll",
r"D:\Yigal\Python36-32\DLLs\tk86t.dll"],
}
base = None
if sys.platform == "win32":
base = "Win32GUI"
# pass # base=None is for console apps
os.environ['TCL_LIBRARY'] = r'D:\Yigal\Python36-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'D:\Yigal\Python36-32\tcl\tk8.6'
setup(name="FFTCalc",
version="0.1",
description="# Rec FFT Calc #",
options={
"build_exe": build_exe_options
},
executables=[Executable("Rec_FFT_GUI.py", base=base)])
This is the output when Graphiz is not installed:
graphviz.backend.ExecutableNotFound: failed to execute ['dot', '-Tjpeg', '-O', 'FFT_RESULTS\\graph'], make sure the Graphviz executables are on your systems' PATH
I can see it is missing the dot.exe ... but how can I pack it with cx_Freeze??

How to use cx_Freeze to make an executable python program

I downloaded cx_Freeze because I'm trying to make a .exe file to share with my platoon and I've been reading through the docs as well as scrolling through cx_Freeze tutorial. After following both of those I still don't know why this isn't working for me. I'm on Python 3.6.2 and I have the path directly setup to the command line.
I tried to launch with setup.py and Julian date 2.py on the desktop and I tried adding them to same folder, but no matter what I try I get back this error when I type python setup.py build, python: can't open file 'setup.py': [Error2] no such file or directory or file exsists. Below is my setup.py code.
from cx_Freeze import setup, Executable
setup(name = "Julian date 2" ,
version = "0.1" ,
description = "" ,
executables = [Executable("Julian date 2.py")])
Another issue I ran into was trying to type cxfreeze Julian date 2.py --target-dir dist I get the error 'cxfreeze' is not recognized as an internal or external command, operable program or batch file.
When you type python setup.py build, you are supposed to be in the directory with setup.py and not anywhere else. So use the command cd to get there.
cx_freeze is not in your path variable so cxfreeze Julian date 2.py --target-dir dist will not work and you have to instead add it to your path (somehow) [not recommended]
Hope this helped.
P.S.
executables = [Executable("Julian date 2.py")]) takes base too. If you want a console application:
executables = [Executable("Julian date 2.py",base='None')])
Gui for windows:
executables = [Executable("Julian date 2.py",base='Win32GUI')])
And you forgot your exe options in setup(). I recommend adapting the setup.py script on cx_freeze doxs:
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}
# GUI applications require a different base on Windows (the default is for a
# console application).
base = "None"
setup( name = "name",
version = "0.1",
description = " ",
options = {"build_exe": build_exe_options},
executables = [Executable("file.py", base=base)])
I solved the first issue, my file was named 'setup.py' and not just 'setup' as it's supposed to be...The name must be setup, the extension .py
Know it's DUMB, after hours, that was the problem...

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

How can I generate a .exe from linux? Python

I have a simple application made ​​in python3, I only have one window and a button, try it with the bdist command:
python setup.py bdist --format=zip
but not working for me.
with: cx_Freeze
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "guifoo",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("text.py", base=base)])
Have any suggestions or recommendations?
a folder is created but I dont see the .exe
If I use images where should I put it?
What about the modules?
What happens if I use relative paths?
Have you tired PyInstaller?
PyInstaller supports cross-compilation:
Add support for cross-compilation: PyInstaller is now able to build Windows executables when running under Linux. See documentation for more details.
More information here
Hope this helps :)

Categories