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

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

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

        os.environ 没有设置环境变量

        os.environ not setting environment variables(os.environ 没有设置环境变量)

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

                  <tbody id='o9rQl'></tbody>
                <tfoot id='o9rQl'></tfoot>

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

                <legend id='o9rQl'><style id='o9rQl'><dir id='o9rQl'><q id='o9rQl'></q></dir></style></legend>
                  本文介绍了os.environ 没有设置环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用 Python 设置 Windows 环境变量.

                  I'm trying to set a Windows environment variable using Python.

                  似乎与文档相反,os.environ 可以获取环境变量但不能设置它们.尝试在 Windows 命令提示符中运行这些:

                  It seems that, contrary to the docs, os.environ can get environment variables but cannot set them. Try running these in a Windows Command Prompt:

                  这行得通:

                  python -c "import os; print(os.environ['PATH'])"
                  

                  这不是:

                  python -c "import os; os.environ['FOO'] = 'BAR'"
                  

                  尝试在命令提示符中键入 set.环境变量 FOO 不存在.

                  Try typing set in the Command Prompt. The environment variable FOO does not exist.

                  如何通过 Python 设置永久的 Windows 环境变量?

                  How can I set a permanent Windows environment variable from Python?

                  推荐答案

                  os.environ[...] = ... 仅在 python 进程期间(或它的子进程).

                  os.environ[...] = ... sets the environment variable only for the duration of the python process (or its child processes).

                  为运行 Python 的 shell 设置变量并不容易(即不使用特定于操作系统的工具),当然也不可取.请参阅 aumo 的评论,了解解决问题的替代方法和有些晦涩的方法.

                  It is not easily (i.e. without employing OS-specific tools) possible and surely not advisable to set the variable for the shell from which you run Python. See aumo's comment for alternative and somewhat obscure approaches to the problem.

                  这篇关于os.environ 没有设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  env: python: No such file or directory(env: python: 没有这样的文件或目录)
                  How to evaluate environment variables into a string in Python?(如何在 Python 中将环境变量评估为字符串?)
                  Python - temporarily modify the current process#39;s environment(Python - 临时修改当前进程的环境)
                  Change current process environment#39;s LD_LIBRARY_PATH(更改当前进程环境的 LD_LIBRARY_PATH)
                  Reading and writing environment variables in Python?(在 Python 中读写环境变量?)
                  When to use sys.path.append and when modifying %PYTHONPATH% is enough(何时使用 sys.path.append 以及何时修改 %PYTHONPATH% 就足够了)

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

                        <bdo id='bNxcH'></bdo><ul id='bNxcH'></ul>

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

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