• <small id='FJH0m'></small><noframes id='FJH0m'>

      <i id='FJH0m'><tr id='FJH0m'><dt id='FJH0m'><q id='FJH0m'><span id='FJH0m'><b id='FJH0m'><form id='FJH0m'><ins id='FJH0m'></ins><ul id='FJH0m'></ul><sub id='FJH0m'></sub></form><legend id='FJH0m'></legend><bdo id='FJH0m'><pre id='FJH0m'><center id='FJH0m'></center></pre></bdo></b><th id='FJH0m'></th></span></q></dt></tr></i><div id='FJH0m'><tfoot id='FJH0m'></tfoot><dl id='FJH0m'><fieldset id='FJH0m'></fieldset></dl></div>
        <bdo id='FJH0m'></bdo><ul id='FJH0m'></ul>

        <legend id='FJH0m'><style id='FJH0m'><dir id='FJH0m'><q id='FJH0m'></q></dir></style></legend>
      1. <tfoot id='FJH0m'></tfoot>

        如何在 Python 中进行环境变量更改?

        时间:2023-07-06
          <bdo id='HIHbN'></bdo><ul id='HIHbN'></ul>
          • <i id='HIHbN'><tr id='HIHbN'><dt id='HIHbN'><q id='HIHbN'><span id='HIHbN'><b id='HIHbN'><form id='HIHbN'><ins id='HIHbN'></ins><ul id='HIHbN'></ul><sub id='HIHbN'></sub></form><legend id='HIHbN'></legend><bdo id='HIHbN'><pre id='HIHbN'><center id='HIHbN'></center></pre></bdo></b><th id='HIHbN'></th></span></q></dt></tr></i><div id='HIHbN'><tfoot id='HIHbN'></tfoot><dl id='HIHbN'><fieldset id='HIHbN'></fieldset></dl></div>

              <legend id='HIHbN'><style id='HIHbN'><dir id='HIHbN'><q id='HIHbN'></q></dir></style></legend>

                <tfoot id='HIHbN'></tfoot>

                  <small id='HIHbN'></small><noframes id='HIHbN'>

                    <tbody id='HIHbN'></tbody>

                  本文介绍了如何在 Python 中进行环境变量更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  根据我的阅读,对 Python 实例中环境变量的任何更改仅在该实例中可用,并且在实例关闭后消失.有什么办法可以通过将它们提交到系统来让它们坚持下去?

                  From what I've read, any changes to the environment variables in a Python instance are only available within that instance, and disappear once the instance is closed. Is there any way to make them stick by committing them to the system?

                  我需要这样做的原因是因为在我工作的工作室中,像 Maya 这样的工具严重依赖环境变量来配置跨多个平台的路径.

                  The reason I need to do this is because at the studio where I work, tools like Maya rely heavily on environment variables to configure paths across multiple platforms.

                  我的测试代码是

                  import os
                  os.environ['FAKE'] = 'C:\'
                  

                  打开另一个 Python 实例并请求 os.environ['FAKE'] 会产生 KeyError.

                  Opening another instance of Python and requesting os.environ['FAKE'] yields a KeyError.

                  注意:可移植性将是一个问题,但我正在编写的小 API 将能够检查操作系统版本并在必要时触发不同的命令.

                  NOTE: Portability will be an issue, but the small API I'm writing will be able to check OS version and trigger different commands if necessary.

                  也就是说,我已经走上了使用 Windows 注册表技术的路线,并且将简单地编写替代方法,以便在需要时调用其他平台上的 shell 脚本.

                  That said, I've gone the route of using the Windows registry technique and will simply write alternative methods that will call shell scripts on other platforms as they become requirements.

                  推荐答案

                  在 Windows 下,您可以使用 这个食谱,虽然看起来有点矫枉过正.

                  Under Windows it's possible for you to make changes to environment variables persistent via the registry with this recipe, though it seems like overkill.

                  为了回应布赖恩的问题,您想要完成什么?可能有更简单的方法.

                  To echo Brian's question, what are you trying to accomplish? There is probably an easier way.

                  这篇关于如何在 Python 中进行环境变量更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Python:修改 PATH 环境变量的平台无关方式 下一篇:为什么python中设置的环境变量不能持久化?

                  相关文章

                • <tfoot id='UNSrG'></tfoot>
                    <bdo id='UNSrG'></bdo><ul id='UNSrG'></ul>

                  <i id='UNSrG'><tr id='UNSrG'><dt id='UNSrG'><q id='UNSrG'><span id='UNSrG'><b id='UNSrG'><form id='UNSrG'><ins id='UNSrG'></ins><ul id='UNSrG'></ul><sub id='UNSrG'></sub></form><legend id='UNSrG'></legend><bdo id='UNSrG'><pre id='UNSrG'><center id='UNSrG'></center></pre></bdo></b><th id='UNSrG'></th></span></q></dt></tr></i><div id='UNSrG'><tfoot id='UNSrG'></tfoot><dl id='UNSrG'><fieldset id='UNSrG'></fieldset></dl></div>

                      <small id='UNSrG'></small><noframes id='UNSrG'>

                      <legend id='UNSrG'><style id='UNSrG'><dir id='UNSrG'><q id='UNSrG'></q></dir></style></legend>