以下是理解我的问题所需的一些上下文(顺便说一下,我的外壳是/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
我的问题:
为什么我的python别名不起作用?(我也试过在
~/.bash_profile
中只包含alias python=python3
,但它仍然没有指向正确的二进制(为什么
python
链接指向(看起来是(python2.7二进制文件,但版本显示3.9.5?#1或#2的答案是否与
brew install
和pip3 install
之间的差异有关?
您使用了错误的命令:
which P
根据定义,在PATH中搜索名为CCD_ 7的可执行文件。
要了解bash实际是如何解释命令的,可以执行
type P
在您的情况下:
type python
顺便说一句,在PATH中给一个别名与一个可执行文件同名可能会让人感到困惑。由于别名的目的是简化在命令行上的键入,我建议您将别名命名为Python,比如py
。