if which python3
does not return the python path, it means your zsh
does not know where it is, which means, either you do not have python3
installed or python3
is not in the environ path
directory.
If you do have python3
installed, you will have to find out where it is and add its path to the environ path
variable. Where python3
is depends on how we install it.
For instance, homebrew
installs packages under the /usr/local/Cellar/
directory. For python3, it will be something like /usr/local/Cellar/python@3.9/3.9.7_1/Frameworks/Python.framework/Versions/3.9/bin/python3.9
.
A convenient way to find out the installed python
versions is to use the applescript library window (I discovered it accidentally). For instance, I have four python versions installed, one came with MacOS (2.7), one came with Xcode (3.8.9), and two were installed with homebrew
(3.9 and 3.10).
homebrew
also creates symlink
s for packages in the /usr/local/bin
folder (it's more complicated and I still need to learn more. for more info., see, e.g., this post). Therefore, we don't need to reference to the full path /usr/local/Cellar/python@3.9/3.9.7_1/Frameworks/Python.framework/Versions/3.9/bin/python3.9
; we may use /usr/local/bin/python3
instead.
If we open the Get info
window of /usr/local/bin/python3
, we can see it points to the original location.
Besides symlink
s, there is also alias
. For instance, when I run which python
on my Mac, it returns
which python
python: aliased to /usr/local/bin/python3
As I just mentioned, /usr/local/bin/python3
is a symlink
pointing to /usr/local/Cellar/python@3.9/3.9.7_1/Frameworks/Python.framework/Versions/3.9/bin/python3.9
.
Enough has been said. It took me a while to gradually understand these things. I hope you are not confused.