Is there a way to update application created with cx_freeze? - python

I have created and distributed a msi file using cx_freeze for my python project. I have made some changes in the project, let's say v2.0. Is there anyway I can update the app in my client computer without having to send the msi again ?
Or is there any other packaging library I can use which will let me do this ?

You can use MSI Upgrade Code for upgrading your application. Check out Create an upgradeable msi file with cx_Freeze for reference.
First, you need to create a UUID (GUID) for the Upgrade Code:
import uuid str(uuid.uuid3(uuid.NAMESPACE_DNS, 'appname.orgname.org')).upper()
You just have to replace'appname.orgname.org' with an appropriate one.
Next, prepare setup.py.
#Application information
name = 'memopad'
version = '1.0.0'
author = 'example'
author_email = 'sample#example.xxx'
url = 'http://example.xxx'
description = 'Text Editor'
#Specify the GUID here (basically it should not be changed)
upgrade_code = '{3F2504E0-4F89-11D3-9A0C-0305E82C3301}'
#For 64-bit Windows, switch the installation folder
# ProgramFiles(64)Folder seems to be replaced with the actual directory on the msi side
programfiles_dir = 'ProgramFiles64Folder' if distutils.util.get_platform() == 'win-amd64' else 'ProgramFilesFolder'
#Options to use with the build command on Windows
build_exe_options = {
'packages': ['os'],
'excludes': ['tkinter'], #Exclude tkinter as it is not used
'includes': ['PySide.QtCore', 'PySide.QtGui', 'gui', 'commands'],
'include_files': ['img/', 'lang/', 'license/'],
'include_msvcr': True, #Since it uses PySide, it cannot be started unless Microsoft's C runtime is included.
'compressed' : True
}
# bdist_Options to use with the msi command
bdist_msi_options = {
'upgrade_code': upgrade_code,
'add_to_path': False,
'initial_target_dir': '[%s]\%s\%s' % (programfiles_dir, author, name)
}
options = {
'build_exe': build_exe_options,
'bdist_msi': bdist_msi_options
}
#exe information
base = 'Win32GUI' if sys.platform == 'win32' else None
icon = 'img/app_icon.ico'
mainexe = Executable(
'main.py',
targetName = 'Memopad.exe',
base = base,
icon = icon,
copyDependentFiles = True
)
setup(
name=name,
version=version,
author=author,
author_email=author_email,
url=url,
description=description,
options=options,
executables=[mainexe]
)
Please note that if you change the UpgradeCode, it will not be considered as the same package and you will not be able to manage the package properly.

Related

Adding an icon for my exe file with CX_freeze

I am converting a .py file to a .exe file using cx_freeze. Which is working but I can not seem to change it so that my .exe file has the custom icon I have. This is what I have tried so far:
'''
import sys
import os
from cx_Freeze import setup, Executable
sys.path.append(os.path.abspath("./src/"))
sys.path.append(os.path.abspath("./src/gui/rc/"))
**Dependencies are automatically detected, but it might need fine tuning.**
buildOptions = {
"packages": ["src.gui",
"src.qt_models",
"src.data",
"src.libs",
"src.tguiil",
"src.graphics"
],
"includes": ["scipy.sparse.csgraph._validation",
"scipy.ndimage._ni_support",
"scipy._distributor_init"
],
"include_files": ["database/"],
"excludes": []
}
installOptions = {}
bdistOptions = {}
base = None
** Uncomment for GUI applications to NOT show cmd window while running.**
if sys.platform =='win32':
base = 'Win32GUI'
executables = [
Executable(script = 'src/facile.py', base=base, targetName = 'facile.exe', icon = 'facade_logo.ico')
]
setup(name='Facile',
version = '1.0',
description = 'A platform for generating Python APIs used to control graphical user interfaces.',
options = {
"build_exe": buildOptions,
"install_exe": installOptions,
"bdist_msi": bdistOptions,
},
executables = executables)
'''
I have no idea what could be wrong.
Figured it out! Just needed to add relative path to file and add distutils as a package to handle external dependencies:
'''
buildOptions = {
"packages": [
# Facile sub-packages
"src.gui",
"src.qt_models",
"src.data",
"src.libs",
"src.tguiil",
"src.graphics",
# External dependencies
"distutils"
],
'''

cx_freeze + selenium + python 3 : No module named 'httplib'

Im trying to buld my app with selenium, i have this setup.py:
import sys
from cx_Freeze import setup, Executable
path_drivers = ( "C:\Python34\Lib\site-packages\PyQt5\plugins\sqldrivers\qsqlmysql.dll", "sqldrivers\qsqlmysql.dll" )
includes = ["atexit","PyQt5.QtCore","PyQt5.QtGui", "PyQt5.QtWidgets","PyQt5.QtSql", "selenium"]
includefiles = [path_drivers]
excludes = [
'_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger',
'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
'Tkconstants', 'Tkinter'
]
packages = ["os"]
path = []
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {
"includes": includes,
"include_files": includefiles,
"excludes": excludes,
"packages": packages,
"path": path
}
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
exe = None
if sys.platform == "win32":
exe = Executable(
script="main.py",
initScript = None,
base=None,
targetName="zeus.exe",
compress = True,
copyDependentFiles = True,
appendScriptToExe = False,
appendScriptToLibrary = False,
icon = None
)
setup(
name = "telll",
version = "0.1",
author = 'me',
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [exe]
)
The build finish with no problems, but when i run my application:
ImportError: No module named 'httplib'
My configuration:
Python 3.4.3 32bit.
PyQt5
Selenium 2.46.0
Thaks for the help
httplib either isn't in your directory path or hasn't been imported.
try adding either of these two scripts to your code:
import httplib
httplib = httplib(config_file="your directory path to httplib")

Initiate CMD console for executable created by cx_Freeze in Python

I have created an application in Python and have made it executable using cx_Freeze.
When the script was not converted into an executable it used to take an input from the cmd (in windows). However, when it is converted into exe it doesn't prompt me for an input.
I have used the following code as setup.py for my script.
includefiles = ["checkPointValueSheets.py"] # include any files here that you wish
includes = []
excludes = []
packages = ["lxml"]
exe = Executable(
# what to build
script = "app.py", # the name of your main python script goes here
initScript = None,
base = None, # if creating a GUI instead of a console app, type "Win32GUI"
targetName = "aflPredictionAutomation.exe", # this is the name of the executable file
copyDependentFiles = True,
compress = True,
appendScriptToExe = True,
appendScriptToLibrary = True,
icon = None # if you want to use an icon file, specify the file name here
)
setup(
# the actual setup & the definition of other misc. info
name = "app", # program name
version = "0.1",
description = 'A general enhancement utility',
author = "K Perkins",
author_email = "",
options = {"build_exe": {"excludes":excludes,"packages":packages,
"include_files":includefiles}},
executables = [exe]
)
Please help me initiating the cmd console the moment I hit enter on my exe.
I am getting this error when executable is run..
Thanks
It is allready in the comment in your code (and in cx_Freezeā€™s documentation, you should simply comment the 2 lines
if sys.platform == "win32":
base = "Win32GUI"
If you let base = None your exe will be a console application (and not a GUI one) and Windows will automatically provide it with a new console if not allready started from one.

Bundling GTK3+ with py2exe

Platform is Windows 7 64bit using python 2.7 and GTK3+ installed from http://sourceforge.net/projects/pygobjectwin32/files/?source=navbar
The exe is compiled but fails to run, due to this
The following modules appear to be missing
['gi.repository.Gdk', 'gi.repository.Gtk', 'overrides.registry']
How can i properly include these files?
imports in my .py file
from gi.repository import Gtk, Gdk
my setup file
#!/usr/bin/env python
from distutils.core import setup
import py2exe, sys
sys.path.append("C:\Python27\Lib\site-packages\gnome")
sys.path.append("C:\Python27\Lib\site-packages\repository")#tried including these extra dirs
sys.path.append("C:\Python27\Lib\site-packages\override")#tried including these extra dirs
sys.path.append("C:\Python27\Lib\site-packages\gi") #tried including these extra dirs
setup(
options = {
'py2exe': {
'bundle_files': 1,
#this does not work 'includes': ['Gtk']
}
},
console=["gui.py"],
zipfile=None
)
The executable error when ran:
ImportError: MemoryLoadLibrary failed loading gi\_gi.pyd
Thanks
You need to add "gi" to "packages".
'options': {
'py2exe': {
'packages': 'gi',
}
}
I haven't tested it on 64bit but this is the setup.py I've used to build with cx_freeze, py2exe looks like is not maintained for a long time.
from cx_Freeze import setup, Executable
import os, site, sys
## Get the site-package folder, not everybody will install
## Python into C:\PythonXX
site_dir = site.getsitepackages()[1]
include_dll_path = os.path.join(site_dir, "gtk")
## Collect the list of missing dll when cx_freeze builds the app
missing_dll = ['libgtk-3-0.dll',
'libgdk-3-0.dll',
'libatk-1.0-0.dll',
'libcairo-gobject-2.dll',
'libgdk_pixbuf-2.0-0.dll',
'libjpeg-8.dll',
'libpango-1.0-0.dll',
'libpangocairo-1.0-0.dll',
'libpangoft2-1.0-0.dll',
'libpangowin32-1.0-0.dll',
'libgnutls-26.dll',
'libgcrypt-11.dll',
'libp11-kit-0.dll'
]
## We also need to add the glade folder, cx_freeze will walk
## into it and copy all the necessary files
glade_folder = 'glade'
## We need to add all the libraries too (for themes, etc..)
gtk_libs = ['etc', 'lib', 'share']
## Create the list of includes as cx_freeze likes
include_files = []
for dll in missing_dll:
include_files.append((os.path.join(include_dll_path, dll), dll))
## Let's add glade folder and files
include_files.append((glade_folder, glade_folder))
## Let's add gtk libraries folders and files
for lib in gtk_libs:
include_files.append((os.path.join(include_dll_path, lib), lib))
base = None
## Lets not open the console while running the app
if sys.platform == "win32":
base = "Win32GUI"
executables = [
Executable("main.py",
base=base
)
]
buildOptions = dict(
compressed = False,
includes = ["gi"],
packages = ["gi"],
include_files = include_files
)
setup(
name = "test_gtk3_app",
author = "Gian Mario Tagliaretti",
version = "1.0",
description = "GTK 3 test",
options = dict(build_exe = buildOptions),
executables = executables
)
Depending on the libraries you have used you might have to add some missing dll, look at the output of cx_freeze.
I've posted the same some time ago on gnome's wiki:
https://wiki.gnome.org/Projects/PyGObject#Building_on_Win32_with_cx_freeze

issues with cx_freeze and python 3.2.2?

I'm trying to freeze a python 3.2.2 script with cx_freeze 4.2.3. PyQt4 is used by the source script, I'm not sure if that is a potential source of the issue. Python crashes during the build process. Here is the command line output:
C:\Python32\New Folder>python setup.py build
running build
running build_exe
copying C:\Python32\Lib\site-packages\cx_Freeze\bases\Win32GUI.exe -> build\exe.win32-3.2\app.exe
copying C:\WINDOWS\system32\python32.dll -> build\exe.win32-3.2\python32.dll
Python itself crashes in Windows at this point and gives the "send error report" MS dialog:
python.exe has encountered a problem and needs to close. We are sorry
for the inconvenience.
Here is my setup.py file:
from cx_Freeze import setup, Executable
GUI2Exe_Target_1 = Executable(
script = "script.pyw",
initScript = None,
base = 'Win32GUI',
targetName = "app.exe",
compress = True,
copyDependentFiles = True,
appendScriptToExe = False,
appendScriptToLibrary = False,
icon = "icon.png"
)
excludes = ["pywin", "tcl", "pywin.debugger", "pywin.debugger.dbgcon",
"pywin.dialogs", "pywin.dialogs.list", "win32com.server",
"email"]
includes = ["PyQt4.QtCore","PyQt4.QtGui","win32gui","win32com","win32api","html.parser","sys","threading","datetime","time","urllib.request","re","queue","os"]
packages = []
path = []
setup(
version = "1.0",
description = "myapp",
author = "me",
author_email = "email#email.com",
name = "app",
options = {"build_exe": {"includes": includes,
"excludes": excludes,
"packages": packages,
"path": path
}
},
executables = [GUI2Exe_Target_1]
)
Any ideas on where I'm going wrong?
edit: After some experimentation it appears the icon I am trying to use is causing issues. It will build if I leave out the icon setting.
Apparently cx_freeze wants icons to be in .ico format. If you try to use a .png for an icon the build process will crash. Also, simply renaming the file extension from .png to .ico does not work, you have actually convert the file to ico.
This may have been obvious to some people but the online docs don't go into detail about required formats for icons.

Categories