I'm using cx_freeze to export a Python program. The exported program was working fine until I tried to add shortcut with icon on the desktop. I've taken the codes from there and there.
When running the main.exe file from its folder in C://Program files, there is no problem, but when I run the shortcut on the desktop there is this error :
The setup.py file :
import sys
from cx_Freeze import setup,Executable
base = None
if sys.platform == "win32":
base = "Win32GUI"
includefiles = ['bouton_ajouter_contact.png','bouton_contacts.png','bouton_deconnexion.png',\
'bouton_message.png','bouton_messages.png','bouton_reglages.png','fond_home.png','worldco.png']
includes = []
excludes = []
packages = ['os']
setup(
...
options = {'build_exe': {'includes':includes,'excludes':excludes,'packages':packages,'include_files':includefiles}},
executables = [Executable(
'main.py', base=base,
shortcutName="Messagerie Cryptee", shortcutDir="DesktopFolder",
icon='messagerie_cryptee_ico.ico'
)]
)
All the .png files and the .ico file are in the same folder as the setup.py file, in Python34. Before adding a shortcut, this problem was not there, and I don't remember having changed anything about images.
Thanks for help
Related
Have created an application using cx_freeze which runs with no issues on my own system but shows the error message shown in the image when the application is downloaded onto a different computer. It looks like its trying to look into my local system rather than the lib file for the modules and don't know how to change that. Have put my setup script below as well.
setup.py
import sys
from cx_Freeze import setup, Executable
includefiles = ['plankton (1).png', 'white_down_arrow.png','white_up_arrow.png','plankton150Model/', 'plankton_icon.ico']
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(
name="Plankton Classifier",
version="0.1",
description="Plankton Classifier",
options= {'build_exe': {'include_files':includefiles}},
executables=[Executable("original_custom_tk.py", base=base)],
)
When I run B.exe (located in c:/my_software/FOLDER_B/B.exe) from A.exe (located in c:/my_software/FOLDER_A/A.exe), both built with cx_Freeze, B.exe (called) tries to find his modules (like IMAGE_B.png, for example) in the A.exe folder (caller), when it would need to search in the B.exe folder. I think this is happening due to some wrong code in setup.py of cx_Freeze.
I use in my script the function os.getcwd() to get the root path in each .exe
This is my setup.py, which I used to build both .exe (A and B)
import os
from cx_Freeze import setup, Executable
import sys
os.environ['TCL_LIBRARY'] = r'c:\python\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'c:\python\tcl\tk8.6'
buildOptions = dict(packages = ["tkinter","os"],
excludes = [],
include_files [r'c:\python\DLLs\tcl86t.dll',
r'c:\python\DLLs\tk86t.dll',
'A.png','icono.ico'])
executables = [Executable('A.py',
base="Console",
icon = "icono.ico")]
setup(name='A',version = '1',
description = 'program A',
options = dict(build_exe = buildOptions),
executables = executables)
See in the cx_Freeze documentation how to use data files. It provides the following code example:
def find_data_file(filename):
if getattr(sys, 'frozen', False):
# The application is frozen
datadir = os.path.dirname(sys.executable)
else:
# The application is not frozen
# Change this bit to match where you store your data files:
datadir = os.path.dirname(__file__)
return os.path.join(datadir, filename)
Please also notice that cx_Freeze version 5.1.1 (the current version) will freeze packages into a lib subdirectory of the build directory, while the main script itself will be frozen in the build directory itself. You might need to modify the above code example accordingly.
So... simple question: I'm trying to use cx_Freeze to build an .exe file.
In my script I import some packages, functions from another .py file and also an array from a .csv file.
How do I compile this into one .exe file / a directory containing an .exe file?
I've noticed that there is a "options" parameter, which I tried filling with
"packages": ["numpy","pandas","userinput","Atoms.csv"]
But no luck. The .exe file just opens and closes again
EDIT
So I've changed the setup.py to
from cx_Freeze import setup,Executable
includefiles = ['Atoms.csv','userinput.py']
includes = []
excludes = []
packages = ['numpy','pandas']
setup(
name = 'Molar mass',
version = '1.0',
description = 'A calculator for the molar mass',
author = '',
options = {'build_exe': {'includes':includes,'excludes':excludes,'packages':packages,'include_files':includefiles}},
executables = [Executable('Molarmass.py')]
)
Which gives me the error "ImportError: No module named 'numpy'"
And if I try to run it without the packages, I can't open the .exe file.
I have a .py file that I am trying to convert into an exe. I have tried numerous tries to build this file using cx_Freeze, but I keep getting the same error every time.
I've heard that it's got something to do with cx_Freeze, so I uninstalled cx_Freeze and reinstalled it using pip install cx_freezexxxx.whl wheel, but that still didn't work. I build my exe by writing python setup.py build in command line. Here's my setup .py code.
import cx_Freeze
import sys
import os
os.environ['TCL_LIBRARY'] = "C:\\Users\\louisa\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Users\\louisa\\tcl\\tk8.6"
base = None
if sys.platform == 'win32':
base = "Win32GUI"
executables = [cx_Freeze.Executable("filemakergui.py", base=base, icon="Treetog-I-Documents.ico")]
cx_Freeze.setup(
name = "ALT File Maker",
options = {"build_exe": {"packages":["tkinter"], "include_files":["Treetog-I-Documents.ico", "Hopstarter-Sleek-Xp-Basic-Help.ico", "Custom-Icon-Design-Flatastic-2-Success.ico"]}},
version = "0.01",
description = "ALT File Maker",
executables = executables
)
Is there anything wrong with what I've written in my setup.py file? I've been stuck on this problem for several days now. Any tips on resolving an issue like this?
I have converted the python script into the exe version. But every time i executed it, it will show the command prompt. Is it possible to change the script to make it not show the command prompt?
Thanks in advance.
Change your .py file extension to .pyw
And then add Win32GUI to your script.
from cx_Freeze import setup, Executable
import sys
if sys.platform == "win32":
base = "Win32GUI"
setup(
name = u"XXX",
version = "1.0",
description = u"XXX",
options = {'build_exe': {'include_files':includefiles}},
executables = [Executable("XXXX.pyw" ,base = base)])