Using cx_Freeze with Graphviz dependency - python

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??

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

create executable from python program with dependencies

I am trying to use cx_Freeze to make an executable for my program.
Even though the python program works perfectly, the executable says it cant file file_cleaner.
This is what the setup.py looks like
import sys
from cx_Freeze import setup, Executable
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')
build_exe_options = {"packages": ["os", "glob", "itertools", "numpy",
"matplotlib", "lmfit", "pandas", "scipy", "pathlib"], "includes": [
"src\\BCS_fit.py", "src\\file_cleaner.py", "src\\__init__.py",
"src\\dependencies\\"], "include_files": ["test\\"]}
base = None
setup(name="BCS processor",
version="0.1",
description="Console application for processing VTS data and fitting it
according to BCS theory",
author="Anil Radhakrishnan",
options={"build_exe": build_exe_options},
executables=[Executable("src\\Master.py", base=base)])
BCS_fit.py and file_cleaner.py are 2 other python files that I call from master.py.
The Dependencies folder has .py and .pyd file from a c module converted to python.
This is the first time I am trying to create an executable for a python script, please excuse any beginner errors.
Thanks a lot for your assistance!
In the past I've used py2exe, not sure if it works with Python 3.6 though,so depends what version you are currently using.
This SO has a quick guide to using cx_Freeze, maybe it covers something that you may have missed out?
Also Pynsist seems to be another very good way of creating an executable from a Python script. It can also create installation files for your program.

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 :)

Python cx_freeze setup script not working

I have a python script that I'd like to freeze. I made the cx_freeze script, and ran it. The .exe works well, but in the frozen script I open a .html file. When the file opens the webbrowser gives me the error "File not found: Firefox cannot find the file at /c:/blah/blah/blah/somefile.html"
As I understand it, this is because cx_freeze is confusing my OS between linux and Windows. However, I'm not sure this is it because I have the code
if sys.platform == "win32":
base = "Win32GUI"
In my setup file. Does anyone know what's going on?
My entire setup file is
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 = "someexe",
version = "0.1",
description = "someexe description",
options = {"build_exe": build_exe_options},
executables = [Executable("someexe.py", base=base)])
copied from the cx_freeze distutils page and edited to fit my needs.
Instead of using os.chdir('C:/path/to/dir'), you should be using os.chdir('C:\path\to\dir'). It's an error in your script, not your cx_freeze setup file.

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