别名未更新 Python 二进制文件

Alias not updating Python Binary

以下是理解我的问题的一些必要上下文(顺便说一句,我的 shell 是 /bin/bash):

~
$ alias
alias dotfiles='/usr/bin/git --git-dir=$HOME/.dotfiles --work-tree=$HOME'
alias ll='ls -al'
alias pip='pip3'
alias python='/usr/local/bin/python3'
~
$ which python
/usr/bin/python
~
$ which python3
/usr/local/bin/python3
~
$ python3 --version
Python 3.9.5
~
$ python --version
Python 3.9.5
~
$ ll /usr/bin/python*
lrwxr-xr-x  1 root  wheel     75 Feb  1  2020 /usr/bin/python -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x  1 root  wheel     82 Feb  1  2020 /usr/bin/python-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
lrwxr-xr-x  1 root  wheel     75 Feb  1  2020 /usr/bin/python2 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x  1 root  wheel     75 Feb  1  2020 /usr/bin/python2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x  1 root  wheel     82 Feb  1  2020 /usr/bin/python2.7-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
-rwxr-xr-x  1 root  wheel  31488 Oct 30  2020 /usr/bin/python3
lrwxr-xr-x  1 root  wheel     76 Feb  1  2020 /usr/bin/pythonw -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7
lrwxr-xr-x  1 root  wheel     76 Feb  1  2020 /usr/bin/pythonw2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7
~
$ ll /usr/local/bin/python*
lrwxr-xr-x  1 marshallmcquillen  admin  38 May 18 06:14 /usr/local/bin/python3 -> ../Cellar/python@3.9/3.9.5/bin/python3
lrwxr-xr-x  1 marshallmcquillen  admin  45 May 18 06:14 /usr/local/bin/python3-config -> ../Cellar/python@3.9/3.9.5/bin/python3-config
lrwxr-xr-x  1 marshallmcquillen  admin  40 May 18 06:14 /usr/local/bin/python3.9 -> ../Cellar/python@3.9/3.9.5/bin/python3.9
lrwxr-xr-x  1 marshallmcquillen  admin  47 May 18 06:14 /usr/local/bin/python3.9-config -> ../Cellar/python@3.9/3.9.5/bin/python3.9-config

我的问题:

  1. 为什么我的 python 别名不起作用? (我也试过 alias python=python3 在我的 ~/.bash_profile 中,但它仍然没有指向正确的二进制文件)

  2. 为什么 python link 指向(看起来是)一个 python2.7 二进制文件,但版本显示 3.9.5?

  3. #1 或#2 的答案是否与 有某种关联?

您使用了错误的命令:

which P

根据定义在 PATH 中搜索名为 P 的可执行文件。

要查看 bash 实际如何解释命令,您可以执行

type P

你的情况:

type python

顺便说一句,给一个别名与 PATH 中的可执行文件同名可能会让人感到困惑。由于别名的目的是简化在命令行上的输入,我建议您将别名命名为 Python 一些简短的名称,例如 py.