Before asking this question have checked other queries (cx_freeze ImportError when executing file) was related to my issue, error was "DLL load failed" but my case is "No module named".
My question is - I have created a Python executables using cx_freeze but when I open the Main.exe file, the application opens with Traceback errors on it..
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {
"optimize": 2,
"includes": [],
"compressed": True,
"copy_dependent_files": True,
"create_shared_zip": False,
"append_script_to_exe": True,
"include_in_shared_zip": False,
"include_files":[('vPlot.ui'),
('vPlot.py'),
('company.jpg')],
"include_msvcr": True,
"packages": [],
}
# 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 = "plcTest",
description = "plcTest!",
options = {"build_exe": build_exe_options},
executables = [Executable("Main.py",
base=base,
copyDependentFiles=True,
appendScriptToExe=True)])
my error is (http://i.imgur.com/TSVg6Ft.png), I can't find the file "'matplotlib.backends.backend_tkagg'", please give your advise, thanks in advance
cx-freeze have good module analysis but sometimes it is fails. Especially back and modules.
Matplotlib uses tkagg (i am not sure it is package name)as backend gui module. To solve this, you have two options;
1- import missing package somewhere in your code
2- pass package name to cx-freeze as parameter.
Example: i used cx-freeze from command-line
cxfreeze FooMain.py --include-module=simplejson, lxml # FooMain.py my main script
edit: using python build_exe_options
"packages": ["simplejson", "lxml"],
Related
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
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??
I am currently trying to use cx_Freeze to create a .exe file for my python scripts.
First, do cx_freeze get all data on the folder into the build folder?
Secondly, I'm having an issue when launching the .exe file. The fact that the first file opens the second one could be the issue ?
The console opened and closed, according to another post on Stackoverflow, I created a .bat file containing :
myfilename.exe%1
pause
to check out what the issue is and I got this issue :
Issue
I've really no idea what to do next since I tried many things on the setup.py to make things working.
Here is the setup.py :
"""setup.py"""
from cx_Freeze import setup, Executable
import os
os.environ['TCL_LIBRARY'] = "C:\\Users\\Roukira\\AppData\\Local\\Programs\\Python\\Python36\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Users\\Roukira\\AppData\\Local\\Programs\\Python\\Python36\\tcl\\tk8.6"
build_exe_options = {"includes": ["tkinter"]}
setup(name="todolist",
version="0.1",
description = "A simple to do list with differnt tabs per account.",
options = {"build_exe": build_exe_options},
executables = [Executable("login_system.py",base=None)])
I'm only using pillow as an external module but it doesn't seem to be the issue.
Thanks for your help by advance !
EDIT : I managed to fix it by adding the ddl missing files path inside the "include_files" option:
build_exe_options = {"packages": ["os", "tkinter"], "include_files": ["to_do_list.py","336sur525.gif","384sur540.gif",
"accounts.txt","button_hide_2.gif","button_quit_2.gif","choose.gif","icone.ico","user.gif",
r"C:\Users\Roukira\AppData\Local\Programs\Python\Python36\DLLs\tcl86t.dll",
r"C:\Users\Roukira\AppData\Local\Programs\Python\Python36\DLLs\tk86t.dll"]}
My script was using a subprocess.call function to call another script, so it didn't work after becoming .exe, I added the .py file inside the "include_files" and it worked as intended.
I'm on Windows 7, as are all potential users of my program. I packaged a Python program I wrote into an executable file using cx_Freeze, with the following command:
python setup.py build
This generates a build directory that contains my_program.exe. The executable works flawlessly on my computer, but on a coworker's machine, it throws an exception:
ImportError: No module named 'zipfile'
Here's my setup.py, where zipfile is explicitly included (and it's definitely in library.zip):
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(
name='Z-Wizard',
version='0.1',
description='Z1/Z2 data extraction tool',
author='Liz Rosa',
author_email='me#url',
options = {
'build_exe': {
'packages': ['zipfile']
}
},
executables = [Executable('my_program.py', base=base)]
)
The traceback is quite long; there's a screenshot at the URL below. It apparently involves a series of functions in _bootstrap.py. I'm not quite sure what's going on here. Also, "C:\Users\lizr..." is my home directory, not hers. Why does it appear in the traceback on her computer? In case it's not obvious, I don't know much about the freezing process.
http://i.imgur.com/cAQKWxq.png
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.