简体   繁体   English

在Windows下自动将Python路径添加到PATH系统变量

[英]add Python path to PATH system variable automatically under Windows

I'm creating one-click python installer (integrated with my application). 我正在创建一键式python安装程序(与我的应用程序集成)。 Is there any way to force Python MSI installer to add python's path to SYSTEM PATH variable? 有什么方法可以强制Python MSI安装程序将python的路径添加到SYSTEM PATH变量? I'm using MSI installer because it is very easy to specify (using command line) how it should interact with the user. 我使用MSI安装程序是因为它非常容易指定(使用命令行)它应如何与用户交互。

There has to be a way, but what some people do is provide batch files that set up the environment before invoking Python. 必须有一种方法,但是有些人要做的是在调用Python之前提供设置环境的批处理文件。 That's what BZR does, anyway. 无论如何,这就是BZR所做的。 If you can write that batch file somewhere that's already normally in the path, so much the better. 如果您可以将该批处理文件写入路径中通常已经存在的位置,那就更好了。

If you're just worried about invoking Python, the normal Python installer does file associations, so you can work it that way. 如果您只是担心调用Python,那么普通的Python安装程序会进行文件关联,因此您可以通过这种方式进行操作。

User variables are stored in the Windows Registry under HKEY_CURRENT_USER\\Environment 用户变量存储在Windows注册表中的HKEY_CURRENT_USER \\ Environment下

I would use winreg in a post install script to set or add to the PATH there. 我会在安装后脚本中使用winreg来设置或添加到那里的PATH中。

http://docs.python.org/library/_winreg.html http://docs.python.org/library/_winreg.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM