windows - How to set an environment variable dependent on another one? (Windows)
问题描述
I am looking for a way on Windows how to set an environment variable dependent on another one. In my case, I want to add the new path to PYTHONPATH
. Let's say, that there is an existing environment variable
%INSTALLATION_DIR% = D:\Programs\MyProject
The easiest way to do that would be:
SETX PYTHONPATH "%PYTHONPATH%;%INSTALLATION_DIR%\Utility\Scripts"
But then, %INSTALLATION_DIR%
is directly replaced by D:\Programs\MyProject
, so PYTHONPATH
is not updated if %INSTALLATION_DIR%
changes.
Is there a way to write the text %INSTALLATION_DIR%
into an environment variable, without evaluating the variable directly?
If possible, I want to do that in an automated way (so using the console, powershell or python), as a want to write a script which adds a list of paths to PYTHONPATH
.
解决方案
我刚刚找到了解决方案。如果环境变量的名称写在引号中,则不会对其进行评估。
SETX PYTHONPATH "%PYTHONPATH%;%"INSTALLATION_DIR"%\Utility\Scripts"
推荐阅读
- python - 接受作为 scikit-learn.predict 方法参数的类型
- flutter - 在 WEB 中运行 Flutter:错误:XMLHttpRequest 错误
- python - 没有名为“PIL”的模块。当我尝试安装它给我一个错误
- java - Java:访问一个类中的属性,该类也是同一个类的对象
- firebase - 如何在 Firestore 中使用多条件
- python - 如何创建二进制数字的无限循环?
- mongodb - 7 月份 MongoDB 聚合中的每日活动总和
- python - 如何使用其他两列(熊猫)中的数据替换一列中的字符串
- amazon-web-services - 如何在 AWS 中有效地聚合数十亿条记录中的数据?
- python - 在 Python 中,哪些变量可以从函数的参数中省略?