This is a very interesting problem,
I was attempting to add an icon to my cx_freeze executable but whenever I do it crashes,
Note: I'm running windows 10 and using python 3.8.2
My setup.py file is as follows:
from cx_Freeze import setup, Executable
import os
include_files = ["res/"]
build_exe_options = {"includes": ["pygame"], "include_files": include_files}
icondir = os.getcwd()+'\icon.ico'
exe = Executable(
script="client.py",
base="Win32GUI",
icon=icondir
)
setup(
name="Syndicate Zero",
version="1.4.0",
author="Wilson F. Wang",
description="Testing Build",
options = {"build_exe": build_exe_options},
executables=[exe]
)
when ran from the directory the main file is located it produces:
running build
running build_exe
copying C:\Users\Wilson\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\cx_Freeze\bases\Win32GUI.exe -> build\exe.win-amd64-3.8\client.exe
copying C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1008.0_x64__qbz5n2kfra8p0\python38.dll -> build\exe.win-amd64-3.8\python38.dll
error: [WinError 2] The system cannot find the file specified: 'build\\exe.win-amd64-3.8\\client.exe'
However, when running without icon="icon.ico" it is able to work without a problem
Current Directory Tree is as follows:
.
|
├── build
│ └── **exe.win-amd64-3.8**
├── util
│ ├── camera.py
│ └── network.py
├── res
│ ├── icon.PNG
│ └── bg.PNG
├── client.py
├── game.py
├── server.py
├── entity.py
├── stats.py
├── **icon.ico**
└── index.html
My Attempts and discovery while working on fixing this problem.
Interesting discovery, when trying to read and open the file that cx_freeze claims it cannot find, it can be read by python with no problem.
Also, I've tried to use an elevated command prompt to run setup in case it was a permissions error to no avail.
Attempting to change the file path of the icon file doesn't fix it either and adding it as it's own include file requirement fails too.
Interestingly while running pyinstaller on the file, the resulting executable doesn't work but does, however, import the icon correctly
I've rewritten the cx_freeze setup code to be more visually cleaner, maybe this could aid in finding the cause of this issue. Also, I've attempted to do the freeze on another laptop with again no success.
Even trying the full path of icon="C:/Users/Wilson/OneDrive - University of Waterloo/Documents/SyndicateZero/SyndicateZero/icon.ico"
CX_Freeze returned the same error.
Hmm, I've watched several tutorials on how to use cx_freeze and freezing the example applications with icons works without a hitch. I wonder if its more effective using pypackage instead
As suggested by @dsgdfg I've modified the icon path to a python os pulled address with no success, however, it was great idea.