1

This seems to show how to set up a post install script, but I am still unclear on how to use it to add the installed directory to the path.

Which values (and where can I find them) do I need to get from the install and how can I refer to them in the post install script itself?

Here is what I have so far, all stolen from other places and stuck together, don't know how to make it work:

import _winreg
import os
from distutils.core import setup
from distutils.command.install import install as _install

REG_PATH = r"SOFTWARE\my_program\Settings"

def _post_install(dir):
    if os.name == 'nt':
        try:
            _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, REG_PATH)
            registry_key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, REG_PATH, 0,
                                           _winreg.KEY_WRITE)
            _winreg.SetValueEx(registry_key, name, 0, _winreg.REG_SZ, value)
            _winreg.CloseKey(registry_key)
            return True
        except WindowsError:
            return False


class install(_install):
    def run(self):
        _install.run(self)
        self.execute(_post_install, (self.install_lib,),
                     msg="Running post install task...")


setup(cmdclass={'install': install})
Community
  • 1
  • 1
user3075082
  • 35
  • 1
  • 6
  • Is the question, how to add a string to the Windows PATH? Which path, User PATH or System PATH? I believe that the install script location will be in the PYTHON2.7\lib\ folder, I haven't worked with this before. Are you on Linux or Windows? –  Jul 17 '14 at 09:57
  • How to add the directory that the user installed to, to the Windows path using a post install script. – user3075082 Jul 17 '14 at 10:27
  • Can you post what code you have? My mind is a bit cloudy at the moment but i believe you need to use Activate(path=None) for your [distribution method](https://pythonhosted.org/setuptools/pkg_resources.html?highlight=path#distribution-methods)?? –  Jul 17 '14 at 10:46
  • @dev247 I have added my code in the original post. That link you posted seems to have a far easier way of doing it, I'll look into that. – user3075082 Jul 17 '14 at 11:01

0 Answers0