This is my cx_freeze setup.py file, with all the modules that I need:
import sys
from cx_Freeze import setup, Executable
import os
os.environ['TCL_LIBRARY'] = "C:\\Users\Maicol\AppData\Local\Programs\Python\\Python36\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Users\Maicol\AppData\Local\Programs\Python\\Python36\\tcl\\tk8.6"
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os",
"numpy",
"tkinter",
"zipfile",
"subprocess",
"time",
"gettext",
"ctypes",
"locale",
"PIL.Image",
"PIL.ImageTk",
"webbrowser",
"feedparser",
"transifex.api",
"polib"],
"includes":["transifex.api.requests.packages.core.idnadata"],
'include_files':['LICENSE',
"changelog.txt",
"tcl86t.dll",
"sld_icon_beta.ico",
"tk86t.dll",
"images",
"icons",
"locale"],
"include_msvcr": True
}
# 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 = "School Life Diary",
version = "0.3",
author="maicol07",
description = "Diario scolastico sempre con te!",
options = {"build_exe": build_exe_options},
executables = [Executable("main.py",
base=base,
icon="sld_icon_beta.ico",
shortcutName="School Life Diary",
shortcutDir="DesktopFolder"),
Executable("settings.py"),
Executable("subjects.py"),
Executable("timetable.py")])
When I build exe and run the main .exe file I get this error:
If you need any other code, just ask me! (See also previous posts for some snippets)
Thanks
Solved by myself removing the includes list and adding "idna" in the packages list.
Code:
import sys
from cx_Freeze import setup, Executable
import os
os.environ['TCL_LIBRARY'] = "C:\\Users\Maicol\AppData\Local\Programs\Python\\Python36\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Users\Maicol\AppData\Local\Programs\Python\\Python36\\tcl\\tk8.6"
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os",
"numpy",
"tkinter",
"zipfile",
"subprocess",
"time",
"gettext",
"ctypes",
"locale",
"PIL.Image",
"PIL.ImageTk",
"webbrowser",
"feedparser",
"requests",
"idna",
"transifex.api",
"polib",
],
#"includes":["transifex.api.requests.packages.core.idnadata"],
'include_files':['LICENSE',
"changelog.txt",
"tcl86t.dll",
"sld_icon_beta.ico",
"tk86t.dll",
"images",
"icons",
"locale"],
"include_msvcr": True
}
# 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 = "School Life Diary",
version = "0.3",
author="maicol07",
description = "Diario scolastico sempre con te!",
options = {"build_exe": build_exe_options},
executables = [Executable("main.py",
base=base,
icon="sld_icon_beta.ico",
shortcutName="School Life Diary",
shortcutDir="DesktopFolder"),
Executable("note.py"),
Executable("settings.py"),
Executable("subjects.py"),
Executable("timetable.py")])
Related
I have trouble to build my setup.py I got this mistake to each attemps... pywintypes.error: (2, 'BeginUpdateResource', 'Le fichier spécifié est introuvable.')
I can't figure out why and where come from this mistake ? If someone could explain to me I would appreciate and be very greateful !
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')
options = {
'build_exe': {
'include_files':[
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
],
},}
includefiles = ["logo.ico", "image.gif"]
target = Executable(
script = "Livre de Compte Bêta.py",
copyright= "Copyright © 2020",
icon = "logo.ico",
base = "Win32GUI")
setup(
name = "Livre de Compte",
version = "0.1" ,
description = "options = {'build_exe': {'include_files':includefiles}}, executables = [target]",
)
instructions:
Change tcl and tk directory according to your file location
Change executable file extension with .pyw, this will hide the console window when you will run your .exe
Remove or add any extra file or folder according to example
Simply run setup.py according to your need
Extra Tip: You can design your installer with inno setup
You can discuss extra question in comment.
You can try this script:
import cx_Freeze
import sys
import os
base = None
if sys.platform == 'win32':
base = "Win32GUI"
os.environ['TCL_LIBRARY'] = r"C:\Python\Python 3.7\tcl\tcl8.6" # Path of tcl
os.environ['TK_LIBRARY'] = r"C:\Python\Python 3.7\tcl\tk8.6" # Path of tk
executables = [cx_Freeze.Executable("app.pyw", # Executable file with .pyw extension
base=base,
icon="Image\shield.ico" # Path of icon
)]
cx_Freeze.setup(
name="Name", # Name of the app
options={"build_exe": {"packages": ["tkinter", "os"],
"include_files": ['tcl86t.dll',
'tk86t.dll',
'Image']}}, # Extra file or folder
description="Write about your app",
executables=executables
)
# Run this command python setup.py bdist_msi, if you want installer and exe
# Run this command python setup.py build, if you want exe only
I made a tkinter application in windows and now I want to make an executable version of it. multiframe.py contains all the the code of the tkinter application.
But when I try to build it I always get syntax error but I don't get it why. Here is a cmd snapshot.
This is how my setup.py looks like:
import cx_Freeze
base = None
if sys.platform == 'Win32':
base = "Win32GUI"
executables = [cx_Freeze.Executable("frame.py"), base=base, icon='ds.ico']
cx_Freeze.setup(
name="cuQ",
options = {"build_exe": {"packages":["tkinter"], include_files=["ds.ico"]},
version= "0.01",
description = "dasdasd",
executables = executables
)
base and icon are options of cx_Freeze.Executable in your code they're not being passed to it. They need to be in () just like "frame.py" is so use:
executables = cx_Freeze.Executable("frame.py", base=base, icon='ds.ico')
In cx_Freeze.setup(options = ... you're first adding a dictionary key "packages" as part of the value for the dictionary key "build_exe" but then suddenly you're trying to add a list include_files instead of a key while still inside the dictionary that is the part of the value alongside "packages" to "build_exe" key. It's hard to describe. Anyway.
Your whole code should look like:
import cx_Freeze, sys
base = None
if sys.platform == 'Win32':
base = "Win32GUI"
executables = cx_Freeze.Executable("frame.py", base=base, icon='ds.ico')
cx_Freeze.setup(
name="cYou",
options = {"build_exe": {"packages":["tkinter"], "include_files":["ds.ico"]}},
version= "0.01",
description = "dasdasd",
executables = executables
)
Below is what I use for tkinter. I just put my tkinter script something.py next to this script. Then I just respond to it something. Some modifications may need to be done in order to include icon files and such:
from cx_Freeze import setup, Executable
import sys, os
fileName = input("What's the name of the py file to be converted to .exe?\n")
sys.argv.append('build')
os.environ['TCL_LIBRARY'] = r'C:\Users\username\AppData\Local\Programs\Python\Python36\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\username\AppData\Local\Programs\Python\Python36\tcl\tk8.6'
base = None
if (sys.platform == "win32"):
base = "Win32GUI" # Tells the build script to hide the console.
elif (sys.platform == "win64"):
base = "Win64GUI" # Tells the build script to hide the console.
setup(
name='KutsalAklinNerde?',
version='0.1', #Further information about its version
description='Parse stuff', #It's description
executables=[Executable(fileName + ".py", base=base)])
First of all, the technical stuff:
Python : 3.3
cx_freeze : 4.3.2
I have looked through several setups, but accomplished nothing. So far I only get a very quickly closing Python Command Line, and sigh, no exe.
The setup.py:
from cx_Freeze import setup, Executable
executables = [
Executable("Swiss Rounds.py", appendScriptToExe=True, appendScriptToLibrary=False)
]
buildOptions = dict(
create_shared_zip = False)
setup(
name = "hello",
version = "0.1",
description = "the typical 'Hello, world!' script",
options = dict(build_exe = buildOptions),
executables = executables)
Thank you people!
It looks like you forgot the base for your executable, so cx freeze doesn't know how to make the exe. This is how I structure my setup.py file. This setup will put the exe in a different folder if it is 32 bit.
import os, sys, platform
from cx_Freeze import setup, Executable
targetDir = "./build/"
build_exe_options = {
"icon": "/assets/images/icon.ico",
"build_exe": "/build/",
"packages": [],
"includes": ["re", "os", "atexit"],
"include_files": ["/assets/"],
"excludes": ["tkinter", "ttk", "socket", "doctest", "pdb", "unittest", "difflib",
"_bz2", "_hashlib", "_lzma", "_socket"],
"optimize": True,
"compressed": True,
}
is32bit = platform.architecture()[0] == '32bit'
if is32bit:
targetDir = "./buildX86/"
build_exe_options["build_exe"] = targetDir
# end
base = None
if sys.platform == "win32":
base = "Win32GUI"
# end
setup( name = "MyProgram",
version = "0.1",
description = "My program example",
options = {"build_exe": build_exe_options},
executables = [ Executable("/myprogram.py",
targetName="MyProgram.exe",
targetDir=targetDir,
base=base) ]
)
Run:
python setup.py build
I've made a .exe file of a game I made in Python, but I'm not sure how to make that exe file have an icon, because it looks dull and boring. I want to somehow make the icon be a picture of an asteroid let's say, because I made the game asteroids. I used cx_freeze to compile it.
Add it to the options in your setup.py file:
setup(
...
options={
"build_exe": {
"icon": "path/to/icon.ico"
}
}
)
This is easier to understand!
import cx_Freeze
import sys
base = None
if sys.platform == 'win32':
base = "Win32GUI"
executables = [cx_Freeze.Executable("example.pyw", base=base)]
cx_Freeze.setup(
name = "SeaofBTC-Client",
options = {"build_exe": {"packages":["tkinter",],"icon":"example.ico"}},
version = "0.01",
description = "Sea of BTC trading application",
executables = executables
)
I have a problem
I have eclipse work space it's contain 4project each project reference from anther project. When I need to make an executable file using cx_Freeze, it can't import the other referenced project to it?
thanks
I tried this code:
base = None
from cx_Freeze import setup, Executable
if sys.platform == "win32":
base = "Win32GUI"
exe = Executable(
script="MyForm.py",
base="Win32GUI",packages=['QtCore', 'QtGui', 'QtSvg','tkinter','time','os','cls_MyForm','threading','sys','DAL','FS_Watch_Collection'],
compress=False, copyDependentFiles=False)
setup(
name = "First Version of File Watcher",
version = "1",
description = "File Watcher Program",
executables = [exe])
and this code:
from cx_Freeze import setup, Executable
#http://www.youtube.com/watch?v=XHcDHSWRCRQ
#http://www.python-forum.org/pythonforum/viewtopic.php?f=4&t=34501&hilit=cxfreeze
includefiles = ['README.txt', 'CHANGELOG.txt']
includes = []
excludes = ['tkinter']
packages = ['pk_LocalStore','QtCore', 'QtGui', 'QtSvg','time','os','threading','sys']
setup(
name = 'First Version of File Watcher',
version = '0.1',
description = 'File Watcher Program',
author = 'ITE CO',
author_email = 'info#from-masr.com',
options = {'build_exe': {'excludes':excludes,'packages':packages,'include_files':includefiles}},
executables = [Executable('MyForm.py')]
)
but it's not working correctly