cx freeze set custom .exe icon - python-3.x

I am converting a .py file to a .exe file using cx_freeze. My current setup file is working but I can not seem to change it so that my .exe file has the custom icon I have made. I have tried a few different ways and none of them seem to be working. Any advice would be very helpful. Thank you for your time.
Attempt one
import sys
from cx_Freeze import setup, Executable
include_files = ['autorun.inf']
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(name = "Calculator",
version = "0.1",
description = "Simple Calculator",
options = {'build_exe':{'include_files':include_files,
'icon':'icon.ico'}},
executables=[Executable("main.py", base = base)])
Attempt Two
import sys
from cx_Freeze import setup, Executable
include_files = ['autorun.inf']
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(name = "Calculator",
version = "0.1",
description = "Simple Calculator",
options = {'build_exe':{'include_files':include_files}},
executables=[Executable("main.py", base = base, icon = 'icon.ico')])

This method should work:
import sys
from cx_Freeze import setup, Executable
include_files = ['autorun.inf']
base = None
if sys.platform == "win32":
base = "Win32GUI"
exe = Executable(script='main.py', base = base, icon='icon.ico')
setup(name = "Calculator",
version = "0.1",
description = "Simple Calculator",
options = {'build_exe':{'include_files':include_files}},
executables = [exe])

Related

Packaging Python file with cx_Freeze

I am trying to package my Python code into an exe file but after following all the instructions on the link below, I managed to build the an exe file but when I try to run it, nothing happens.
https://cx-freeze.readthedocs.io/en/latest/distutils.html
My setup.py file is
import sys
from cx_Freeze import setup, Executable
build_exe_options = {"packages": ["os","tkinter", "pandas" , "openpyxl", "datetime", "time"]}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "login",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("login.py", base=base)])
My login file runs without any error on Anaconda.
Can someone comment what may cause the problem?

bdist_mac cx_freeze with tkinter and selenium interaction

I created a python 3 application that has a tkinter GUI and selenium action upon clicking a button. Here is the setup.py file:
from cx_Freeze import setup, Executable
import sys
import os
from pathlib import Path
buildOptions = {"include_files":['execute.py'], "packages": ['encodings'], "includes": ['numpy.core._methods', 'numpy.lib.format'], "excludes": []}
if sys.platform=='win32':
base = "Win32GUI"
else:
base=None
executables = [
Executable('bot_gui.py', base=base)
]
home_path = str(Path.home())
user_txt_path = []
if sys.platform=='win32':
print("windows detected")
user_txt_path.append('\\user.txt')
else:
print("macos detected")
user_txt_path.append('/user.txt')
#for initialization
f = open(home_path + user_txt_path[0], "w+")
for i in range(12):
f.write("---\n")
setup(name='tachysloth',
version = '1.0',
description = 'test',
options = dict(build_exe = buildOptions),
executables = executables)
The problem is when I run python setup.py build, everything works fine; but when I run python setup.py bdist_mac, the GUI works when you click on the application (called tachysloth-1.0 below)
but when I click on a button to in the GUI to open google.com on Chrome, the button does not do anything.
If you need more information to assess this problem, please let me know and I will provide that information as soon as possible.
Thank you again.

Cannot fix pywintypes.error: (2, 'BeginUpdateResource', 'The system cannot find the file specified.')

I am trying to build an .exe file of my Python application. I have tried various ways to create a setup file from both Github and Stackoverflow and I keep getting this same error:
pywintypes.error: (2, 'BeginUpdateResource', 'The system cannot find the file specified.').
I am using Python 3.6.1, and cx_Freeze to build the application.
Here are the different setup files I have tried:
Attempt 1:
import os.path
from cx_Freeze import setup, Executable
os.environ['TCL_LIBRARY'] = r'C:\Users\RedCode\AppData\Local\Programs\Python\Python36-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\RedCode\AppData\Local\Programs\Python\Python36-32\tcl\tk8.6'
executables = [Executable("myprogram.py", base="Win32GUI")]
options = {
'build_exe': {
'include_files': [
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
]
},
}
setup(
name="Standalone.exe",
options=options,
version="0.1",
description='Simple tkinter application',
executables=executables, requires=['cx_Freeze', 'cx_Freeze']
)
Attempt 2:
from cx_Freeze import setup, Executable
import sys
import os
productName = "My Program"
if 'bdist_msi' in sys.argv:
sys.argv += ['--initial-target-dir', r'C:\Users\RedCode\PycharmProjects\Standalone' + productName]
sys.argv += ['--install-script', 'myprogram.py']
os.environ['TCL_LIBRARY'] = r'C:\Users\RedCode\AppData\Local\Programs\Python\Python36-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\RedCode\AppData\Local\Programs\Python\Python36-32\tcl\tk8.6'
exe = Executable(
script="myprogram.py",
base="Win32GUI",
targetName="Product.exe"
)
setup(
name="Standalone.exe",
version="1.0",
author="Me",
description="Copyright 2012",
executables=[exe],
scripts=[
'myprogram.py'
]
)
Attempt 3:
import sys
import os
from cx_Freeze import setup, Executable
build_exe_options = {"packages": ["os"], "includes": ["tkinter"]}
def s_SourceFile():
if (sys.argv[0] == ''):
return __file__
else:
return sys.argv[0]
os.environ['TCL_LIBRARY'] = r'C:\Users\stefano.demattia\AppData\Local\Programs\Python\Python36-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\stefano.demattia\AppData\Local\Programs\Python\Python36-32\tcl\tk8.6'
setup(name="Standalone",
version="0.1",
description="My GUI application!",
options={"build_exe": build_exe_options},
executables=[Executable("myprogram.py", base="Win32GUI", targetName="Standalone.exe")])
Attempt 4:
application_title = "Car Database"
main_python_file = "cardb.py"
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(
name = "myprogram.py",
version = "0.1",
description = "Simple embedded database application",
executables = [Executable("myprogram.py", base = base)])
I have also tried pyinstaller but it keeps giving me a tuple out of range error no matter what I do, and I tried bbfreeze which I can't even get to install. I have checked my files and everything is there, so I do not see how it can still tell me a specified file is not found.
What else can I do or how can I edit the above attempts so that the application actually builds properly? Is there even a way to determine which file is missing?
Remove the version, I got the same error, looked at the code and noticed it was referencing versioning in the source, so thought I'd try it, and it fixed it for me.
I know the poster probably no longer needs this, but posting it for others that come across this in the future since I didn't see the answer anywhere else.
cx_Freeze.setup(
name="SampleName",
options={"build_exe": {"packages": ["tkinter", "os"],
"include_files": ['tcl86t.dll', 'tk86t.dll', 'closenew.png', 'sujata.png', 'config.py', 'ui_attributes.py']}},
version="0.01", # Remove this line
description="Tkinter Application",
executables=executables
)
I have removed the version and it worked.
cx_Freeze.setup(
name="SampleName",
options={"build_exe": {"packages": ["tkinter", "os"],
"include_files": ['tcl86t.dll', 'tk86t.dll', 'closenew.png', 'sujata.png', 'config.py', 'ui_attributes.py']}},
description="Tkinter Application",
executables=executables
)

cx_freeze gives input and file errors

I've seen similar problems on different forums, but none applies to this.
I have two files, one 'main.py' and the main program 'xlsKonverter.py' which I want to use cx_freeze to compile to an .exe file. When building the .exe I get this error message:
pywintypes.error: (110, 'EndUpdateResource', 'The system cannot open the device or file specified.')
And when trying to run the (somewhat finished) build, this Exception pops up:
I've tested all of my code, so the error is not there. It must be somewhere within the setup file. Am I wrong? And what would be a good fix?
'setup.py'
This is my cx_freeze setup
import sys
from cx_Freeze import setup, Executable
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}
packages = ['xlrd', 'glob', 'sys']
includes = ['xlsKonverter']
includefiles = []
eggsacutibull = Executable(
script = "main.py",
base = 'Console',
initScript = None,
targetName = "main.py",
compress = True,
copyDependentFiles = True,
appendScriptToExe = False,
appendScriptToLibrary = False,
icon = None
)
setup( name = "Table Converter",
version = "0.3",
author = "Jørgen Sirhaug",
description = "Makes a .csv file from designated Wire List.",
options = {"build_exe": build_exe_options},
executables = [eggsacutibull]
)
'main.py'
, my main function
import xlsKonverter as xk
import os.path
import sys
def main():
fileList = xk.getAllFileURLsInDirectory("C:\\Users\\Jørgen\\Dropbox\\Aker\\Wire Lists\\")
if len(fileList) < 1:
print("ERROR! No files in directory!\nDoes the specified folder excist?")
else:
print('')
for i in range(len(fileList)):
try:
sheet = xk.getWorksheet(fileList[i])
tagCols = xk.automaticFirstRow(sheet)
pairedList = xk.pairCells(sheet, tagCols)
csvString = xk.makecsv(pairedList)#, tagCols)
xk.writeToFile(csvString, i)
except:
print("ERROR!\n" + fileList[i] + '\nThis file does not excist!')
main()
and the imports from 'xlsKonverter.py'
import xlrd
import glob
import sys
Try putting an encoding declaration in your main.py file. That's a comment that looks like this:
# encoding: cp1252
You might have to change the last bit depending on how you're saving the file. If it's created on Windows, cp1252 is normal for Western Europe. On Linux and Mac, utf8 is more common.

How does cxFreeze include internal project modules?

Update:
I suspect this is an error in cxFreeze as I understand this should
go automatically.
end update
Update:
I missed an error given by cxFreeze:
Missing modules:
? Test.MyClass imported from main__main__
end update
I'm not sure what the proper term is for modules within project unlike sys or PyQt, so I'm going with internal project modules.
I have some example code below where I recieve the error "ImportError: cannot import name MyClass." and I would love to know how to get cxFreeze to compile that 'Test.py' module.
Here's my main code:
Main.py
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
#from guiObjects.MainWindow import MainWindow
from Test import MyClass
if __name__ == "__main__":
# Initializing the main window
app = QApplication(sys.argv)
widget = QMainWindow()
#mainWindow = MainWindow(widget)
test = MyClass()
widget.show()
sys.exit(app.exec_())
Test.py
class MyClass(object):
def __init__(self):
pass
__init.py__
'''empty'''
Setup.py
import sys
from cx_Freeze import setup, Executable
path_platforms = ( "C:\Python33\Lib\site-packages\PyQt5\plugins\platforms\qwindows.dll", "platforms\qwindows.dll" )
includes = ["re","sip","atexit","PyQt5.QtCore","PyQt5.QtGui"]
includefiles = [path_platforms]
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="Win32GUI",
targetDir = r"dist",
targetName="Main.exe",
compress = True,
copyDependentFiles = True,
appendScriptToExe = False,
appendScriptToLibrary = False,
icon = None
)
setup(
name = "Main",
version = "0.1",
author = 'me',
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [exe]
)
This problem happens when you run setup.py in a subfolder of where Main.py is located.
I now placed my setup.py in the same folder as Main.py. and changed my .bat file to python ../setup.py build install.
This seems to be a bug in cx_Freeze as it works fine for Python 2.7, but not Python 3.3.
Your test.py is wrong, you can't leave functions empty, try
class MyClass(object):
def __init__(self):
pass
and in setup.py mabye add "Test" into "includes"
includes = ["re","sip","atexit","PyQt5.QtCore","PyQt5.QtGui", "Test"]

Resources