1 """Add Python to the search path on Windows
3 This is a simple script to add Python to the Windows search path. It
4 modifies the current user (HKCU) tree of the registry.
6 Copyright (c) 2008 by Christian Heimes <christian@cheimes.de>
7 Licensed to PSF under a Contributor Agreement.
15 HKCU = _winreg.HKEY_CURRENT_USER
21 pythonpath = os.path.dirname(os.path.normpath(sys.executable))
22 scripts = os.path.join(pythonpath, "Scripts")
23 appdata = os.environ["APPDATA"]
24 if hasattr(site, "USER_SITE"):
25 userpath = site.USER_SITE.replace(appdata, "%APPDATA%")
26 userscripts = os.path.join(userpath, "Scripts")
30 with _winreg.CreateKey(HKCU, ENV) as key:
32 envpath = _winreg.QueryValueEx(key, PATH)[0]
37 for path in (pythonpath, scripts, userscripts):
38 if path and path not in envpath and os.path.isdir(path):
41 envpath = os.pathsep.join(paths)
42 _winreg.SetValueEx(key, PATH, 0, _winreg.REG_EXPAND_SZ, envpath)
46 paths, envpath = modify()
48 print "Path(s) added:"
49 print '\n'.join(paths[1:])
51 print "No path was added"
52 print "\nPATH is now:\n%s\n" % envpath
54 print _winreg.ExpandEnvironmentStrings(envpath)
56 if __name__ == '__main__':