7

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.

  • If anyone would like to replicate this problem or have a go at freezing the application yourself, my entire code will be available for download here https://github.com/FengchiW/SyndicateZero. Thanks in advance! – Wilson Wang Jul 02 '20 at 02:49
  • 1
    At the moment, the `icon.ico` file is not at the root of your project, but in `res/`. Have you tried with `icon=res/icon.ico` or to put the icon at the root of your project? – zezollo Jul 02 '20 at 03:37
  • @zezollo Yeah I have, I've tested move the icon file into a plethora of different combinations of locations – Wilson Wang Jul 02 '20 at 03:40
  • 1
    `icon` is a resource file or callable static file ? Did you have any idea about of `which directory include cx_freeze extracting files ?` somewhere type `icondir = os.getcwd()+'\res\my_awesome.ico'` (don't forget differences of ("\" and "/")(" " and "\ " ) etc.) – dsgdfg Jul 07 '20 at 22:00
  • @dsgdfg I tried your fix to unfortunately no success, however, I will continue to perform more details tests with your idea thanks – Wilson Wang Jul 07 '20 at 22:58
  • @WilsonWang Friend, you're going to have a lot of problems with this. My advice to you is that you write one `C` program, even if it's not big. It is difficult to write applications without knowing how `malloc` and `mmap` functions work. `a=[1,2]; b=[3,4];` than `a[2:] == b >> True` – dsgdfg Jul 11 '20 at 10:33
  • Does your application rely on `numpy+mkl`? I had a similar issue using numpy > 1.17.4+mkl, it disappeared when I could use a version compiled with MKL 2020.0.1 (I used numpy 1.18.4+mkl). See https://github.com/numpy/numpy/issues/15431 and https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Loading-MKL-2020-mkl-core-dll-resets-the-DLL-search-order-on/td-p/1179421 – jpeg Jul 30 '20 at 06:40

0 Answers0