Initiate CMD console for executable created by cx_Freeze in Python - 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.

Related

Is there a way to update application created with cx_freeze?

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.

In cx_freeze setup function, what do the name, version, and description keywords actually do?

When I freeze my code using cx_freeze, I usually include name, version, and description keyword arguments in the setup function because that's what's done in documentation examples. But I can't figure out how these keyword arguments actually affect the output of the setup script. If I ignore or omit these keyword arguments, is it going to cause any problems? Below is the example code from the documentation for reference.
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}
# 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 = "guifoo",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("guifoo.py", base=base)])
Hey dear the name is the NAME of the output .exe (application), the description is the description of the app you have made, the description will be shown as the name of the task (application) in the task manager and at last the version is the version of your application..
Thanks

Database not being displayed after build

I'm using cx_Freeze to build my executable. I used Pyqt4 and the QtSql modules to display my database, the problem is when running through the python script, the database is displayed and the table works fine but when i run it as an executable the table does not work properly and nothing is displayed. When running as script:
When running as an executable:
Any reason as to why? Is this some bug for cx_Freeze?
Here is my code for creating the table:
self.ProductModel = QtSql.QSqlRelationalTableModel()
self.ProductModel.setTable("Product")
self.ProductModel.setRelation(6, QtSql.QSqlRelation("ProductType","ProductTypeID","Type"))
self.ProductModel.select()
fields = ["Product ID", "Product Name", "In Stock", "Expiry Date", "Stock Alert", "Price", "Product Type"]
for count in range(len(fields)):
self.ProductModel.setHeaderData(count, QtCore.Qt.Horizontal, fields[count])
edit = QtSql.QSqlTableModel.OnManualSubmit
self.ProductModel.setEditStrategy(edit)
self.ProductView = QtGui.QTableView()
self.ProductView.setModel(self.ProductModel)
self.ProductView.setSelectionMode(self.mode)
self.ProductView.setItemDelegate(ProductDelegate())
self.ProductView.sortByColumn(0,QtCore.Qt.AscendingOrder)
self.ProductView.setSortingEnabled(True)
There should be nothing wrong with this as everything works fine during the script.
and here's the setup script code for cx_Freeze:
from cx_Freeze import setup, Executable import sys import matplotlib
base = None if sys.platform == 'win32':
base = 'Win32GUI'
executables = [Executable("Main.py", base = base)] includes = ['matplotlib', 'PyQt4.QtSql'] setup(name = 'Test',
options = {"build_exe" : {"includes" : includes }},
version = '0.18',
description = 'Test',
executables = executables)
I was struggling with the same issue, but on another question (here in stackoverflow) I found the solution is copying the folder sqldrivers (mine was at C:\Python34\Lib\site-packages\PyQt5\plugins) into your executable directory

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.

exe error with cx_freeze

Hey am relatively new to compiling python scripts to exe. Im using cx_freeze to compile my scripts and once its built i run the exe and it gives me this error. Have google around alot but not too sure. Error is:
Cannot import traceback module.
Exception: No module named re
Original Exception: No module named re
Not too sure how to go about fixing this. I read that possibly there is a clash between a module named re? in python? and a module named re in cx_freeze module?
My setup file looks like:
from cx_Freeze import setup, Executable
includes = []
includefiles = ['remindersText.pkl']
eggsacutibull = Executable(
script = "podlancer.py",
initScript = None,
base = 'Win32GUI',
targetName = "podlancer.exe",
compress = True,
copyDependentFiles = True,
appendScriptToExe = False,
appendScriptToLibrary = False,
icon = None
)
setup(
name = "Podlancer",
version = "0.1",
author = 'jono',
description = "Podlancer UI script",
options = {"build_exe": {"includes":includes, "include_files": includefiles}},
executables = [eggsacutibull]
)
Try to change
includes = []
to
includes = ["re"]
That worked for me
cx_freeze will barf if the runtime working directory is not the directory that the executable is in.
Is re the first import you do? What happens when you do them in a different order?
Meeting this same problem putting re in includes didn't work for me. It produced a cx_Freeze.freezer.ConfigError when rebuilding the .py file.
import sys
from cx_Freeze import setup, Executable
build_exe_options = {'include_files': ['re']}
setup( name = "Foreground Window Montior",
version = "0.1",
description = "Query the foreground window.",
options = {'build_exe': build_exe_options},
executables = [Executable("actWin_Query.py")])
If I put re in packages rather than in include_files it did not produce this compile error.
import sys
from cx_Freeze import setup, Executable
build_exe_options = {"packages": ["re"]}
setup( name = "Foreground Window Montior",
version = "0.1",
description = "Query the foreground window.",
options = {'build_exe': build_exe_options},
executables = [Executable("actWin_Query.py")])

Categories