I am new to Python and cx_Freeze. Please help me to get it working.
And run the command:
python setup.py build
It is giving me the following error.
Missing modules:
? System imported from serial.serialcli
? TERMIOS imported from serial.serialposix
? clr imported from serial.serialcli
? wx imported from wxversion
I am using the following setup.py file.
# Let's start with some default (for me) imports...
from cx_Freeze import setup, Executable
# Process the includes, excludes and packages first
includes = []
excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger',
'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
'Tkconstants', 'Tkinter']
packages = []
path = []
GUI2Exe_Target_1 = Executable(
# what to build
script = "..\esp\main.py",
initScript = None,
base = 'Win32GUI',
targetDir = r"dist",
targetName = "acup_new.exe",
compress = True,
copyDependentFiles = True,
appendScriptToExe = False,
appendScriptToLibrary = False,
icon = None
)
setup(
version = "0.1",
description = "No Description",
author = "No Author",
name = "cx_Freeze Sample File",
options = {"build_exe": {"includes": includes,
"excludes": excludes,
"packages": packages,
"path": path
}
},
executables = [GUI2Exe_Target_1]
)
Based on this question, it seems like you may need to add these modules to the includes[] list in your setup.py file.
I don't recall having to do this when using cx_Freeze, but I'll edit this answer once I can find more information.
Related
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")])
I have a pretty hefty python script that I'm trying to cx_freeze, however when I run the executable file I keep getting the same error and it appears to be related to the docx module.
I'm using Python 3.3.5 with docx 0.7.6-py33 on a Windows 8.1 machine.
This is my setup script.
from cx_Freeze import setup, Executable
includefiles = ['logo.ico','db.db','dbloc.bin']
includes = []
excludes = []
packages = ['tkinter','docx','sys', 'sqlite3', 'os', 'hashlib', 'random', 'uuid', 'base64', 'tempfile', 'win32api',
'winreg', 'ntplib', 'winsound', 'time', 'csv', 'webbrowser', 'inspect','datetime', 'decimal', 'ctypes',
'win32com.client','operator']
exe = Executable(
# what to build
script = "NEPOS.py",
initScript = None,
base = 'Win32GUI',
targetName = "Nepos.exe",
copyDependentFiles = True,
compress = True,
appendScriptToExe = True,
appendScriptToLibrary = True,
icon = 'Icon.ico'
)
setup(
name = "MyProgram",
version = "1.0.0",
description = 'Description',
author = "Joe Bloggs",
author_email = "123#gmail.com",
options = {"build_exe": {"excludes":excludes,"packages":packages,
"include_files":includefiles}},
executables = [exe]
)
This is the error I'm getting.
It looks like it is having trouble finding methods that belong to docx, but my source code calls import docx and it is listed as a dependent module in the setup file so I'm not sure why they aren't being included.
After a LOT of messing about I've finally cracked this. The docx module is dependent on lxml. Even though the raw .py file runs perfectly fine with just docx imported, when cx_freezing you need to explicitly state the dependency by adding lxml to the packages.
At present I am using pyinstaller for bundling my python application. I am equally migrating to pyGObject (due to pygtk being depreciated).
Now pyinstaller does not support pyGObject and I have as of yet not figured out the required hooks... One of the other downsides of pyinstaller is how it bundles into a single executable - it causes the company installed virus scanner to check quite intensively every time the exe is run ==> quite slow startup.
Looking into using cx_freeze due to the pyGObject & py3 support I note it does not have a single-executable option. That in itself isn't an issue if the working directory can be cleaned up, be it via the pyd/dll being bundled into a second zip or into a subdirectory.
Searching around (stackoverflow and other sites), it is illuded to that it can be done, but I am not getting the expected results. Any idea#s?
setup.py is based around this one: http://wiki.wxpython.org/cx_freeze
ok solved:
1) setup.py
import sys
from cx_Freeze import setup, Executable
EXE1 = Executable(
# what to build
script = "foo.py",
initScript = None,
base = 'Win32GUI',
targetDir = "dist",
targetName = "foo.exe",
compress = True,
copyDependentFiles = True,
appendScriptToExe = True,
appendScriptToLibrary = False,
icon = 'foo.ico'
)
setup(
version = "9999",
description = "...",
author = "...",
name = "...",
options = {"build_exe": {"includes": includes,
"excludes": excludes,
"packages": packages,
"path": sys.path,
"append_script_to_exe":False,
"build_exe":"dist/bin",
"compressed":True,
"copy_dependent_files":True,
"create_shared_zip":True,
"include_in_shared_zip":True,
"optimize":2,
}
},
executables = [EXE1]
)
2) foo.py header:
import os
import sys
if getattr(sys,'frozen',False):
# if trap for frozen script wrapping
sys.path.append(os.path.join(os.path.dirname(sys.executable),'bin'))
sys.path.append(os.path.join(os.path.dirname(sys.executable),'bin\\library.zip'))
os.environ['TCL_LIBRARY'] = os.path.join(os.path.dirname(sys.executable),'bin\\tcl')
os.environ['TK_LIBRARY'] = os.path.join(os.path.dirname(sys.executable),'bin\\tk')
os.environ['MATPLOTLIBDATA'] = os.path.join(os.path.dirname(sys.executable),'bin\\mpl-data')
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 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