在 mac 上更改 python 路径?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3696124/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 12:18:03  来源:igfitidea点击:

changing python path on mac?

python

提问by Tim

I would like to change PATH from Python 2.6.1 to 3.1.2. I have both versions installed on my computer but when I type python --version in the terminal I get Python 2.6.1 so thats the current version its "pointing" to. Now if I type Python3.1 it changes the current version to the one I want to use, though the PATH is still 2.6.1. Downloaded with the Python 3.1 package comes a Update Shell Profile.command, so when I run it and then run nano ~/.bash_profile it says there: Setting PATH for Python 3.1 the orginal version is saved in .bash_profile.pysave PATH="/Library/Frameworks/Python.framework/Versions/3.1/bin:${PATH}" export PATH.

我想将 PATH 从 Python 2.6.1 更改为 3.1.2。我的计算机上安装了这两个版本,但是当我在终端中键入 python --version 时,我得到了 Python 2.6.1,因此这是它“指向”的当前版本。现在,如果我输入 Python3.1,它会将当前版本更改为我想要使用的版本,尽管 PATH 仍然是 2.6.1。与 Python 3.1 包一起下载的是更新 Shell Profile.command,所以当我运行它然后运行 ​​nano ~/.bash_profile 时,它​​说: Setting PATH for Python 3.1 the original version is saved in .bash_profile.pysave PATH="/ Library/Frameworks/Python.framework/Versions/3.1/bin:${PATH}" 导出路径。

Does this mean that I have changed the PATH or does it just give me instructions how to?!

这是否意味着我已经更改了 PATH 或者它只是给了我如何操作的说明?!

Regards

问候

采纳答案by leoluk

PATH="/Library/Frameworks/Python.framework/Versions/3.1/bin:${PATH}" 
export PATH

This will append the Python directory to the path.

这会将 Python 目录附加到路径中。

If this is part of ~/.bash_profile, this will append the Python path on each startup.

如果这是 的一部分~/.bash_profile,这将在每次启动时附加 Python 路径。

回答by Vineesh TP

try the below lines

尝试以下几行

cd /usr/local/bin
cp python3.7 python

Then restart terminal

然后重启终端

回答by Jux Salley

i managed to fixed mine by removing python2, i don't if it's a good practice

我设法通过删除 python2 修复了我的问题,如果这是一个好习惯,我不会

回答by AliyuIbn

For those using a .zsh terminal instead of .bash, you might need to update your PATH using the command:

对于使用 .zsh 终端而不是 .bash 的用户,您可能需要使用以下命令更新 PATH:

nano .zsh

Then update your PATH with the export command.

然后使用 export 命令更新您的 PATH。

See the link below for more guide:
https://coolestguidesontheplanet.com/how-to-add-to-the-shell-path-in-macos-using-terminal/

有关更多指南,请参阅以下链接:https:
//coolestguidesontheplanet.com/how-to-add-to-the-shell-path-in-macos-using-terminal/