user:~> which python
/usr/bin/python
user:~> type python
python is /usr/bin/python
user:~> ls -la /usr/bin/python
lrwxrwxrwx 1 root root 7 Oct 8 13:26 /usr/bin/python -> python2
#!/bin/bash
TOGGLE=$HOME/.python3Active
if [ ! -e $TOGGLE ]; then
touch $TOGGLE
sudo ln -fs python3 /usr/bin/python
ls -la /usr/bin/python
echo "Press any key to continue..."
read
else
rm $TOGGLE
sudo ln -fs python2 /usr/bin/python
ls -la /usr/bin/python
echo "Press any key to continue..."
read
fi
首先,确认默认的“python”链接到什么,以便可以引用它,并确保哪个和shell一致:
现在您可以在shell中添加一个别名来覆盖它。在
按照shahaf的建议,打开bash的~/.bash_配置文件或zsh的~/.zshrc文件(look here for historical reasons behind the files used),然后添加一行别名,例如,quick方法:
^{pr2}$新别名将为您启动的下一个shell设置,或者,打开一个新的终端窗口并获取配置文件以使其处于活动状态。例如,在bash中:
或者,将符号链接更改为默认情况下指向python3,并记住该更改(我使用一个简单的切换脚本,否则任何缺少python2包的安装都可能导致对直接使用python符号链接的configure脚本的投诉):
Catalina现在使用
zsh
作为默认值,而不是Bash。在验证您在终端中使用的是
echo $0
类型的shell将
alias python='python3'
添加到$HOME/.zshrc您必须编辑终端的配置文件,通常位于
~/.profile
下在那里添加别名行,这个文件在终端会话启动时被加载,并导出环境变量和方法,以便在该会话中可以访问它们
我建议使用更健壮、更强大的终端增强,比如Z-Shell
相关问题 更多 >
编程相关推荐