Python cx_freeze 4.3.4: Setting targetName causes errors

好久不见. 提交于 2019-12-06 11:45:08

Reposting as an answer:

targetName is the filename of the executable it's going to produce. On Windows, executables must have a .exe extension, so you'll need to set it as 'hello.exe' rather than just 'hello'.

I ran into this problem with the latest version of Cx_freeze.

I found that I needed to change my Executable call in the setup.py to use a relative path for the dist directory.

Changes needed in setup.py

From

MyExe_Target_1 = Executable(
    # what to build
    script = "main.py",
    initScript = None,
    base = None,
    targetDir = r"dist", 
    targetName = "MyWindowsApp.exe",
    compress = True,
    copyDependentFiles = True,
    appendScriptToExe = False,
    appendScriptToLibrary = False,
    icon = None
    )

To:

MyExe_Target_1 = Executable(
    # what to build
    script = "main.py",
    initScript = None,
    base = None,
    targetDir = r".\\dist",  # needs in Windows format relative to the working dir!
    targetName = "MyWindowsApp.exe",
    compress = True,
    copyDependentFiles = True,
    appendScriptToExe = False,
    appendScriptToLibrary = False,
    icon = None
    )
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!