日期:2024-06-29 浏览次数:348 次
创建符号链接:
首先,确认您的 Python 3 路径。通常在 /usr/bin 或 /usr/local/bin 下:
which python3
假设路径是 /usr/bin/python3,接下来创建一个符号链接,将 python 指向 python3。
ln -sf /usr/bin/python3 /usr/bin/python
更新 alternatives 系统(适用于一些 Linux 发行版,如 CentOS 或 Fedora):
使用 alternatives 系统来管理多个版本的 Python。
首先,添加 Python 3 到 alternatives 系统:
alternatives --install /usr/bin/python python /usr/bin/python2.7 1 alternatives --install /usr/bin/python python /usr/bin/python3.6 2
然后,设置默认的 python 版本为 Python 3:
alternatives --set python /usr/bin/python3.6
验证更改:
执行以下命令,确认 python 已指向 Python 3:
python --version
如果您需要针对特定的用户设置默认的 Python 版本,可以在用户的 shell 配置文件中进行设置,例如 .bashrc 或 .bash_profile:
echo 'alias python=python3' >> ~/.bashrc source ~/.bashrc
这样,在当前用户的 shell 会话中,python 命令会指向 Python 3。