invalid syntax at cx_Freeze executables - python

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

Related

python - cx_freeze - Error about external module transifex.api

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")])

cx_freeze shortcut doesn't work

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.

cx_Freeze help: is there a way to NOT make console open?

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

Set an icon for a .exe file

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
)

how can reference from one Eclipse project to another when using cx_freeze

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

Categories

Resources