I know there are many related questions to this problem, but I have yet to come across a solution that's helped me. I'm relatively new to using the terminal, so any and all insight will be massively appreciated!
I have Python3.7 installed on my laptop (Mac M1). In my terminal, when I type
which python3
the output is,
/usr/bin/python3
When I type,
echo $PATH
the output is,
”/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Library/Apple/usr/bin:/usr/local/bin/python3
Finally, when I try,
python3 --version
the output is,
python3: error: can't exec '/Applications/Xcode.app/Contents/Developer/usr/bin/python3' (errno=No such file or directory)
I'm very confused because the path in the error isn't in my $PATH.
CodePudding user response:
As you have /usr/bin
first in your path, when you just run python3
, the shell will pick up /usr/bin/python3
. Now, that’s not a real Python interpreter. You can tell that from the fact that its link count is 76. That means that it is one of 76 different names for the same program! These are “shims” that Apple install in /usr/bin
, which just hand over control to various developer tools installed as part of Xcode. That is why, when you try to run it, you get an error message talking about Xcode.
I do not fully understand how those shims work, and why the supposedly-Xcode-installed Python is not available on your system, so I will not delve further into that. (My guess is that xcode-select
figures somewhere in the answer...)
However, if you have installed Python manually in the /usr/local
hierarchy, it might be a good idea to fix your PATH
variable so that /usr/local/bin
appears before /usr/bin
. Theat way, then you run python3
, you get the one you installed, not the Apple one.
CodePudding user response:
Thanks to the information provided, I found a solution that works. The following PATH did the trick:
/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin