将cx_Freeze msi添加到路径

时间:2018-06-15 18:01:59

标签: python python-3.x path cx-freeze

我有一个msi,安装后我希望它将exe添加到路径。

我发现了这个:

  

add_to_path将目标目录添加到PATH环境变量中;如果有任何基于控制台的可执行文件,则默认值为True,否则为

来自the documentation

我尝试将其添加到设置脚本中:

setup(  name = "cabbage",
        version = "0.1",
        description = "just a vegetable",
        add_to_path = True, # <-- Just here
        options = {"build_exe": build_exe_options},
        executables = [Executable("spam.py", base=base)])

返回:

  

UserWarning:未知的分发选项:'add_to_path'

我也尝试过命令行:

C:\Users\Simon\Desktop>python setup.py bdist_msi add_to_path=True
invalid command name 'add_to_path=True'

如何添加此选项?

1 个答案:

答案 0 :(得分:1)

在setup.py脚本中添加以下行以使其正常工作。

  if 'bdist_msi' in sys.argv:

        sys.argv += ['--add-to-path', 'True']

您的代码应如下所示:

 if 'bdist_msi' in sys.argv:

        sys.argv += ['--add-to-path', 'True']


 setup(  name = "cabbage",
    version = "0.1",
    description = "just a vegetable",
    add_to_path = True, # <-- Just here
    options = {"build_exe": build_exe_options},
    executables = [Executable("spam.py", base=base)])

运行命令:python setup.py bdist_msi