Search code examples
pythonpython-3.xpathcx-freeze

Adding cx_Freeze msi to path


I have an msi and when installed I want it to add the exe to path.

I have found this:

add_to_path add the target directory to the PATH environment variable; the default value is True if there are any console based executables and False otherwise

From the documentation.

I have tried adding this to the setup script:

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)])

This returns:

UserWarning: Unknown distribution option: 'add_to_path'

I also tried from the command line:

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

How do I add this option?


Solution

  • Add below lines in your setup.py script to make it work.

      if 'bdist_msi' in sys.argv:
    
            sys.argv += ['--add-to-path', 'True']
    

    Your code should look like:

     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)])
    

    Run command: python setup.py bdist_msi