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')
Related
I've built an app using Tkinter, and when compiling it with cx_Freeze I get no issues.
When I run the .exe generated on my machine, and my virtual test machine, I have no issues. However, someone currently testing my app is encountering this issue:
Previously they had been encountering this issue:
I fixed the issue of 'brotlicffi' not being found by bypassing py7zr by throwing it into a try statement, as it's not completely essential for the app to function. However, cefpython3 is.
What I find very confusing is that the paths in the traceback errors are all my paths, I've encountered this before with cx_Freeze, which threw me off at first but dismissed it as a possible quirk of cx_Freeze/Python.
Here is my cx_Freeze setup.py:
dir_path = os.getcwd()
interface_path = os.path.join(dir_path, "interface")
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
options = {"build_exe": {
"packages": [
"base64",
"re",
"os",
"inspect",
"_winapi",
"json",
"time",
"selenium",
"webdriver_manager",
"tqdm",
"pdfrw",
"cefpython3",
"customtkinter",
"tkinter",
"pyglet",
"urllib",
"py7zr",
"brotli",
"brotlicffi", # Needed for py7zr
"winreg",
"requests",
"shutil",
"stat",
"inspect"
],
# "path": [
# "C:\\Users\\aaron\\PycharmProjects\\slowly scraper\\venv\\Lib\\site-packages"
# ],
"include_files": [
# "yellow.json",
("venv\\Lib\\site-packages\\brotli.py", "lib\\brotli.py"),
"interface"
# "cefpython3"
]
# "replace_paths": [("*", "")]
}
}
executables = [cx_Freeze.Executable(
"main.py",
base=base,
target_name="SLD.exe",
icon=os.path.join(interface_path, "SLD_icon.ico")
)
]
cx_Freeze.setup(
name="Slowly Letter Downloader",
options=options,
author="PastaSource",
version="0.1",
description="Automates the downloading of letters from Slowly",
executables=executables
)
If it helps, I'm running this all in Pycharm, the includes the compilation of the cx_Freeze application.
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.
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
I want to create a .exe file. I'm using Python 2.7.3 with wxPython for the GUI. I've installed py2exe for Python 2.7 and tried to create a .exe file following the tutorial at http://www.py2exe.org/index.cgi/Tutorial
When I try to run my created .exe file, I get following error:
File "wx\_gdi.pyc",line823, in BitmapFromImage wx._core.PyAssertionError:
C++ assertion "image.OK()" failed at ..\..\src\msw\bitmap.cpp(802) in
wxBitmap::CreateFromImage(): invalid image
So I looked into my code and the following line is causing the problem:
self.bmpSun = wx.StaticBitmap(self, wx.ID_ANY, wx.BitmapFromImage(wx.Image('images/sun.gif', wx.BITMAP_TYPE_ANY)), pos = (0,0))
When I browse to the source folder and run the main.py file myself, my app runs fine. I haven't found any help online so far. Can anybody solve this problem/suggest reliable alternatives for py2exe? Thank you.
The line that errors out is looking for an image in the Images folder. That's a path relative to the .exe file created by py2exe. So you need to be sure that that folder exists in correct position relative to the exe, and that it is populated with the images you are going to use. You can do this 2 ways. Either copy the folder to where the exe will reside, or use the data_files keyword arg in the script that makes the .exe. Here's the pertinent part of one of my setup scripts, showing a data_files list of tuples and use of the data_files keyword arg later:
data_files = [('Images', glob('Images/*.*')),
]
includes = ['win32com.decimal_23', 'datetime']
excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'pywin.debugger',
'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
'Tkconstants', 'Tkinter', 'unittest']
packages = []
dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll',
'tk84.dll','MSVCP90.dll']
setup(
data_files = data_files,
options = {"py2exe": {"compressed": 2,
"optimize": 2,
"includes": includes,
"excludes": excludes,
"packages": packages,
"dll_excludes": dll_excludes,
"bundle_files": 1,
"dist_dir": "dist",
"xref": False,
"skip_archive": False,
"ascii": False,
"custom_boot_script": '',
}
},
zipfile = None,
windows = [filename]
)
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.