Python cx_freeze setup script not working - python

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.

Related

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

Python crashes when trying to compile using cx_Freeze

I'm trying to compile my python scripts using cx_Freeze, here is my setup file:
import cx_Freeze
import sys
import matplotlib
import os
base = None
if sys.platform == 'win32':
base = "Win32GUI"
os.environ['TCL_LIBRARY'] = r'C:\\Python35\\tcl\\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\\Python35\\tcl\\tk8.6'
executables = [cx_Freeze.Executable("HomeScreen.py", base=base,
icon="icon.png")]
cx_Freeze.setup(
name = "LeagueBoost",
options = {"build_exe":{"packages": ["sqlite3","requests","time","sys","os","statistics","matplotlib","random","collections"],
"include_files": ["Assets", "LeagueBoost_v1.py","LBRun.py","graphSetup.py","profilepage.py","Assets_rc.py"]}},
version = "1",
executables = executables
)
But when I give the cmd command C:/python35/python.exe, it gets to copying C:\python35\python35.dll -> build\exe.win-amd64-3.5\python35.dll it pops up "python has stopped working"
This is crazy
after hitting my head against the wall for the weird reason python crashes when I tried to build executable with cx_Freeze,
what solved my problem is using ico format for icon file.
Your icon file should be icon type not png, may be because png is not supported by cx_Freeze.
In your setup.py change
icon="icon.png" to icon="icon.ico",
please note the icon file must be in ico format, don't act smart and just change the extension.
If it still doesn't work you can give it a trial without writing this option at all icon="icon.png" and see if it works.

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

cx_Freeze copies path

I am using cx_Freeze to generate a windows binary for my PyQt app. But the binary installer that is generated seems to still contain references to files on MY machine. (The one that generated the binary). So I can't distribute the generated installer to other machines. When the program is launched on another machine it seems look for paths that only exist on my machine.
my setup.py looks like this:
import sys
from cx_Freeze import setup, Executable
""" To build on windows: python.exe setup.py bdist_msi """
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "Checkout",
version = "0.1",
description = "",
options = {"build_exe" : {"includes": "atexit"}},
executables = [Executable("checkout.py", base=base)])

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