简体   繁体   English

如何在 Mac 上将 Python3 设置为默认 python 版本?

[英]How to set Python3 as a default python version on Mac?

Is there a way to set the Python 3.8.3 as the default Python version on macOS Catalina -- version 10.15.2?有没有办法将 Python 3.8.3 设置为 macOS Catalina 上的默认 Python 版本 - 版本 10.15.2?

Steps I have done:我已经完成的步骤:

  1. Look where it is installed.看看它安装在哪里。
ls -l /usr/local/bin/python*

The output I got is something like this:我得到的 output 是这样的:

lrwxr-xr-x  1 jeena  admin  36 Mar 20  2019 /usr/local/bin/python -> ../Cellar/python@2/2.7.16/bin/python
lrwxr-xr-x  1 jeena  admin  39 May 20 12:43 /usr/local/bin/python-build -> ../Cellar/pyenv/1.2.18/bin/python-build
lrwxr-xr-x  1 jeena  admin  43 Mar 20  2019 /usr/local/bin/python-config -> ../Cellar/python@2/2.7.16/bin/python-config
lrwxr-xr-x  1 jeena  admin  37 Mar 20  2019 /usr/local/bin/python2 -> ../Cellar/python@2/2.7.16/bin/python2
lrwxr-xr-x  1 jeena  admin  44 Mar 20  2019 /usr/local/bin/python2-config -> ../Cellar/python@2/2.7.16/bin/python2-config
lrwxr-xr-x  1 jeena  admin  39 Mar 20  2019 /usr/local/bin/python2.7 -> ../Cellar/python@2/2.7.16/bin/python2.7
lrwxr-xr-x  1 jeena  admin  46 Mar 20  2019 /usr/local/bin/python2.7-config -> ../Cellar/python@2/2.7.16/bin/python2.7-config
lrwxr-xr-x  1 root   wheel  69 May 20 12:22 /usr/local/bin/python3 -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/python3
lrwxr-xr-x  1 root   wheel  76 May 20 12:22 /usr/local/bin/python3-config -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/python3-config
lrwxr-xr-x  1 root   wheel  71 May 20 12:22 /usr/local/bin/python3.8 -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8
lrwxr-xr-x  1 root   wheel  78 May 20 12:22 /usr/local/bin/python3.8-config -> ../../../Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8-config
lrwxr-xr-x  1 jeena  admin  37 Mar 20  2019 /usr/local/bin/pythonw -> ../Cellar/python@2/2.7.16/bin/pythonw
lrwxr-xr-x  1 jeena  admin  38 Mar 20  2019 /usr/local/bin/pythonw2 -> ../Cellar/python@2/2.7.16/bin/pythonw2
lrwxr-xr-x  1 jeena  admin  40 Mar 20  2019 /usr/local/bin/pythonw2.7 -> ../Cellar/python@2/2.7.16/bin/pythonw2.7
  1. Change the default python symlink to the version I want to use from above:从上面将默认的 python 符号链接更改为我要使用的版本:
ln -s -f /usr/local/bin/python3.8 /usr/local/bin/python2.7

Then I checked the version again:然后我再次检查了版本:

python --version

And I got it as --> Python 2.7.16我得到它 - > Python 2.7.16

I also tried alias python="/usr/bin/python3.8" but sadly it's still Python 2.7.16我也试过alias python="/usr/bin/python3.8"但遗憾的是它仍然是 Python 2.7.16

I think you can run the following commands:我认为您可以运行以下命令:

rm /usr/local/bin/python
ln -s /usr/local/bin/python3.8 /usr/local/bin/python

And in your ~/.zshrc or ~/.bashrc, put在你的 ~/.zshrc 或 ~/.bashrc 中,放

export PATH=/usr/local/bin:$PATH

Then start a new terminal to test然后启动一个新的终端进行测试

echo $PATH

to make sure /usr/local/bin is before /usr/bin确保 /usr/local/bin 在 /usr/bin 之前

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

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