-2

Below is some necessary context for understanding my questions (my shell is /bin/bash by the way):

~
$ 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

My Questions:

  1. Why is my alias for python not working? (I've also tried just having alias python=python3 in my ~/.bash_profile and it still doesn't point to the correct binary)

  2. Why does the python link point to (what appears to be) a python2.7 binary, but the version shows 3.9.5?

  3. Is the answer to #1 or #2 somehow related to the difference between brew install and pip3 install?

alex
  • 10,900
  • 15
  • 70
  • 100
m_squared
  • 105
  • 9
  • 2
    when you run program then system first get path from `alias` which points to `python3`. When you use `which` then it doesn't check aliases but only real files - probably set with `update-alternatives` – furas May 19 '21 at 10:21
  • 2
    It _is_ working for all we can see. When you run `python --version` it outputs what we expect. The real question here is probably ["why is `which` the wrong tool?"](https://unix.stackexchange.com/questions/85249/why-not-use-which-what-to-use-then) – tripleee May 19 '21 at 10:53

1 Answers1

1

You are using the wrong command:

which P

by definition searches for an executable named P in the PATH.

To see how a command is actually interpreted by bash, you could do a

type P

in your case:

type python

BTW, it can become confusing to give an alias the same name as an executable in your PATH. Since the purpose of an alias is to simplify typing on the command line, I suggest that you name your alias to Python something short, like py.

user1934428
  • 19,864
  • 7
  • 42
  • 87