简体   繁体   English

如何在 Mac 上将 Python 的默认版本设置为 3.0.0

[英]How to set Python's default version to 3.0.0 on Mac

The Python's default version is 2.7.0 on my MacOS,在我的 MacOS 上,Python 的默认版本是 2.7.0,

python --version
Python 2.7.16

python3 --version
Python 3.9.9

and Python3 has been installed via homebrew, how to make it as default?并且已经通过自制软件安装了 Python3,如何将其设置为默认值? I want to make it point to the correct directory instead of using alias.我想让它指向正确的目录而不是使用别名。

type -a python        
python is /usr/bin/python

type -a python3
python3 is /opt/homebrew/bin/python3
python3 is /usr/bin/python3

Also, it would be very grateful if you can help with pip also.此外,如果您也能对 pip 提供帮助,我们将不胜感激。 So far only pip3 has been installed.到目前为止,只安装了 pip3。

type -a pip 
pip not found

type -a pip3
pip3 is /opt/homebrew/bin/pip3
pip3 is /usr/bin/pip3

Generally doing this can impact legacy programs reliant on Python 2.x , but the below was taken from a website to demonstrate how to change the default .通常这样做会影响依赖于Python 2.x遗留程序,但以下内容取自网站以演示如何更改默认设置

How to set Python3 as a default python version on MacOS?如何在 MacOS 上将 Python3 设置为默认 python 版本?

This has been answered on this website, and the below are snippets from the website这个问题已经在这个网站上得到了回答,下面是来自网站的片段

https://dev.to/malwarebo/how-to-set-python3-as-a-default-python-version-on-mac-4jjf#:~:text=Change%20Python%20Version%20MacHow%20to%20set%20Python3%20as,how%20it%20should%20be%20done%3A%20More%20items...%20 https://dev.to/malwarebo/how-to-set-python3-as-a-default-python-version-on-mac-4jjf#:~:text=Change%20Python%20Version%20MacHow%20to%20set %20Python3%20as,how%20it%20should%20be%20done%3A%20More%20items...%20

Look where python is installed & view the output.查看 python 的安装位置并查看 output。

ls -l /usr/local/bin/python*

Change the default python symlink to the version you want to use from above.从上面将默认的 python 符号链接更改为您要使用的版本。 Note that, we only need to choose the one that end with python3.*.请注意,我们只需要选择以python3.*结尾的那个。 Please avoid using the ones' that end with config or python3 **.*** m or python3 .* m-config .请避免使用以configpython3 **.*** mpython3 .* m-config结尾的那些。 Below command shows how it should be done:下面的命令显示了它应该如何完成:

ln -s -f /usr/local/bin/python3.7 /usr/local/bin/python

Close the current terminal session or keep it that way and instead open a new terminal window关闭当前终端 session 或保持这种方式,而是打开一个新终端 window

python --version

在此处输入图像描述

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

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