简体   繁体   English

如何更改 MAC cmd 中的默认 python3 路径?

[英]How can I change the default python3 path in MAC cmd?

My Mac has contained multiple python versions so that I would like to fix one as my default python.我的 Mac 包含多个 python 版本,因此我想将其中一个修复为我的默认 python。

In the current, it has set the path of anaconda python.目前已经设置好了anaconda python的路径。 I have stopped to use the anaconda-python.我已经停止使用 anaconda-python。 蟒蛇_蟒蛇

And I would like to change the python3 as default following with path:我想将 python3 更改为默认路径:

/usr/local/bin/python3

How can I do this?我怎样才能做到这一点?

Hope:希望:

  • python3 as default that path python3 作为默认路径

  • jupyter notebook would follow that path jupyter notebook 将遵循该路径

  • pip3 install package would follow that path pip3 安装包将遵循该路径

您可以通过编辑 .bashrc 文件来更改此路径

export PATH="/usr/local/bin/python3:${PATH}"

Update your environment variable PATH to include your required python path.更新环境变量 PATH 以包含所需的 python 路径。 Append the python path in the beginning of the environment variable PATH, so that first it'll look in that path.在环境变量 PATH 的开头附加 python 路径,以便它首先在该路径中查找。

You need to update that in .bash_profile file.您需要在 .bash_profile 文件中更新它。 For that go to the root path and look for the mentioned file.为此,请转到根路径并查找提到的文件。 Run ls-a to check whether the file is present.运行 ls -a 检查文件是否存在。

cd ~
ls -a

Open the file打开文件

vi .bash_profile

Add below commands in the file (press i to go into insert mode)在文件中添加以下命令(按 i 进入插入模式)

# Setting PATH for Python
export PATH={ur path}:$PATH

(Save the file by pressing :wq) (按 :wq 保存文件)

Check whether the update is made by running检查是否通过运行进行更新

echo $PATH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM