cx_Freeze: shortcutDir gives error

醉酒当歌 提交于 2019-12-11 05:38:03

问题


I'm creating a single file exe for my Python program. I'm using cx_Freeze. Everything works perfect except one little annoying thing.

When I install my program everything installs as it should do, including the shortcut on my desktop.

BUT...When I want to start the program with the shortcut on the desktop I get the following error:

When I try to run my program from within my program folder than it works. When I manually create a shortcut to the desktop than it works aswell.

Does anyone know why the shortcut, which is installed at the installation of my program doesn't work?

My cx_Freeze setup.py

import cx_Freeze
import sys

executables = [cx_Freeze.Executable("Tennis_Calculator.py", base="Win32GUI", icon="tennis_ball.ico", shortcutName="TPC", shortcutDir="DesktopFolder")]
build_exe_options = {"icon": "tennis_ball.ico","packages":["Tkinter", "csv", "ttk"], "include_files":["tennis_ball.ico", "testtennis.csv"]}
build_msi_options = {"include_files":"testtennis.csv"}


cx_Freeze.setup(
    name = "Tennis Probability Calculator",
    options = {"build_exe":build_exe_options, "build_msi":build_msi_options},
    version = "1.0",
    author = "WS",

    executables = executables
    )

回答1:


After a long search I found a solution.

How to set shortcut working directory in cx_freeze msi bundle?

I was able to fix the problem by making a small change to cx_Freeze/windist.py. In add_config(), line 61, I changed:

msilib.add_data(self.db, "Shortcut",
        [("S_APP_%s" % index, executable.shortcutDir,
                executable.shortcutName, "TARGETDIR",
                "[TARGETDIR]%s" % baseName, None, None, None,
                None, None, None, None)])

to

msilib.add_data(self.db, "Shortcut",
        [("S_APP_%s" % index, executable.shortcutDir,
                executable.shortcutName, "TARGETDIR",
                "[TARGETDIR]%s" % baseName, None, None, None,
                None, None, None, "TARGETDIR")]) # <--- Working directory.

Thanks everyone.



来源:https://stackoverflow.com/questions/38637337/cx-freeze-shortcutdir-gives-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!