Python not working on Mac OS M1 asking to install cmd developer tools

Type on terminal python returns the following error:

daniloassis@d ~ % python
python: error: Failed to locate 'python'.
xcode-select: Failed to locate 'python', requesting installation of command line developer tools.
daniloassis@d ~ % which python 
/usr/local/bin/python
daniloassis@ ~ % xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

Then, ask to install the command developer tools. I install it and type python again and keep returning error and not working.

which python returns a path /usr/local/bin/python and this file is pointed to the python3.

lrwxr-xr-x 1 daniloassis wheel  16 Aug 19 12:50 python -> /usr/bin/python3

I already:

  • tried to uninstall and install python
  • reinstall the xcode
  • install command line tools several times
  • update the software

But, nothing worked for me.

Does anyone know how to fix this bug?

Post not yet marked as solved Up vote post of daniloab Down vote post of daniloab
4.8k views

Replies

Did you symlink /usr/local/bin/python manually?

/usr/bin/python3 is an Xcode tool shim which you cannot symlink to as it maps its path and filename to the current Xcode install. eg /usr/bin/python3 -> /Applications/Xcode.app/Contents/Developer/usr/bin/python3

Workaround is to symlink directly to python3 in your Xcode or Xcode command line tools install. eg

sudo rm /usr/local/bin/python

sudo ln -s /Applications/Xcode.app/Contents/Developer/usr/bin/python3 /usr/local/bin/python
OR
sudo ln -s //Library/Developer/CommandLineTools/usr/bin/python3 /usr/local/bin/python

Alternatively change your scripts to use python3

try python3 on zsh

Hardware: Apple silicon