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
)
Related
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)])
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")])
Hello I'm a newbie in python.
I am trying to make an msi file.
It works fine when I run the exe file in the built directory.
But the shortcut that I made on the DesktopFolder won't work.
The reason seems like the shortcut file can't reference UI files.
When I copy & paste the UI files on the DesktopFolder, it does work.
Is there a way to execute shortcut file properly without moving UI files?
Here's my source code.
import sys
from cx_Freeze import setup, Executable
company_name = '####'
product_name = 'Robot Parser V1.0'
exebuildOptions = dict(packages=[],
excludes=[],
includes=['atexit'],
include_files=['qwed.ui', 'sub.ui'])
bdist_msi_options = { 'upgrade_code': '{parser-04291986}',
'add_to_path': False,
'initial_target_dir': r'[ProgramFilesFolder]\%s\%s' % (company_name, product_name)}
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
executables = [Executable('__init__.py', base=base, shortcutName="Robot.ini Parser V1.0",
shortcutDir="DesktopFolder")]
setup(name='Roboparser',
version='0.1',
description='Sample cx_Freeze PyQt4 script',
options={'build_exe' : exebuildOptions, 'bdist_msi': bdist_msi_options},
executables=executables
)
Thank you for your help in advance.
I am trying to convert a python game (made with pygame) into a exe file for windows, and I did using cx_Freeze. No problems there.
The thing is that when I launch myGame.exe, it opens the normal Pygame window and a console window(which I do not want).
Is there a way to remove the console window? I read most of the documentation, but I saw nothing really (except base, but I don't get what that is).
BTW, here is my setup file:
import cx_Freeze
exe = [cx_Freeze.Executable("myGame.py")]
cx_Freeze.setup(
name = "GameName",
version = "1.0",
options = {"build_exe": {"packages": ["pygame", "random", "ConfigParser", "sys"], "include_files": [
"images", "settings.ini", "arialbd.ttf"]}},
executables = exe
)
Here's a screen shot of what happens when I launch the exe:
So what was wrong, was that the setup.py file was missing a parameter.
What you need to add is base = "Win32GUI" to declare that you do not need a console window upon launch of the application.
Here's the code:
import cx_Freeze
exe = [cx_Freeze.Executable("myGame.py", base = "Win32GUI")] # <-- HERE
cx_Freeze.setup(
name = "GameName",
version = "1.0",
options = {"build_exe": {"packages": ["pygame", "random", "ConfigParser", "sys"],
"include_files": ["images", "settings.ini", "arialbd.ttf"]}},
executables = exe
)
The parameter can be passed also by the shell if you are making a quick executable
like this:
cxfreeze my_program.py --base-name=WIN32GUI
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