为什么我要将 python 添加到 PATH
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34900042/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why would I add python to PATH
提问by Permian
I am beginning to look at python, so when I found a tutorial it said that the first thing to do would be to download python from www.python.org/downloads/
我开始看python,所以当我找到一个教程时,它说首先要做的是从www.python.org/downloads/下载python
Now when I downloaded python 3, I then started the installation and got to
现在,当我下载 python 3 时,我开始安装并到达
Why would I want to "Add Python 3.5 to PATH"? What is PATH? Why is it not ticked by default?
为什么我要“将 Python 3.5 添加到 PATH”?什么是路径?为什么默认不打勾?
采纳答案by SuperBiasedMan
PATH is an environment variable in Windows. It basically tells the commandline what folders to look in when attempting to find a file. If you didn't add Python to PATH then you would call it from the commandline like this:
PATH 是 Windows 中的环境变量。它基本上告诉命令行在尝试查找文件时要查找的文件夹。如果您没有将 Python 添加到 PATH 中,那么您可以像这样从命令行调用它:
C:/Python27/Python some_python_script.py
Whereas if you add it to PATH, you can do this:
而如果将其添加到 PATH,则可以执行以下操作:
python some_python_script.py
Which is shorter and neater. It works because the command line will look through all the PATH folders for python
and find it in the folder that the Python installer has added there.
哪个更短更整洁。它之所以有效,是因为命令行将查看所有 PATH 文件夹python
并在 Python 安装程序添加到那里的文件夹中找到它。
The reason it's unticked by default is partly because if you're installing multiple versions of Python, you probably want to be able to control which one your commandline will open by default, which is harder to do if bothversions are being added to your PATH.
默认情况下不勾选它的部分原因是如果您安装多个版本的 Python,您可能希望能够控制默认情况下打开哪个命令行,如果将两个版本都添加到您的 PATH 中,这将更难做到.
回答by Moshe Shitrit
In addition to what @SuperBiasedMan stated, you can edit your PATH in Windows by hitting Start > Run, then type sysdm.cpl
.
From there, navigate to Advanced tab and then hit Environment Variables.
In the lower section, where it says 'System variables', find the one named PATH and double click it. Note that it would be easier to copy and paste it to a notepad or something. The separator as you can see is a semi-colon.
Any path that you add to this variable, will be looked when you type any command in a cmd window or through the 'Run' command line.
That's the same concept as in Linux, I just pointed out how it can be edited.
除了@SuperBiasedMan 所说的之外,您还可以通过点击开始 > 运行在 Windows 中编辑您的 PATH,然后输入sysdm.cpl
. 从那里,导航到高级选项卡,然后点击环境变量。在下方显示“系统变量”的部分,找到名为 PATH 的变量并双击它。请注意,将其复制并粘贴到记事本或其他东西会更容易。如您所见,分隔符是一个分号。当您在 cmd 窗口中或通过“运行”命令行键入任何命令时,将查看您添加到此变量的任何路径。这与 Linux 中的概念相同,我只是指出了如何对其进行编辑。