When I build/run/archive my app in Xcode (on MacOS 12.3) I encounter this error:
env: python: No such file or directory
Command Ld failed with a nonzero exit code
I think I might have changed something with regard to my python environment while working on a school project or messed something up there. However, I can not figure out what is wrong.
I tried reinstalling Xcode and python (using brew and pyenv). I also relinked python using brew. But I still encounter the same error.
Which python gives the following results:
which python3
-> /usr/local/bin/python3
And in my ~/.zshrc I have the following line:
export PATH=/usr/local/bin:/usr/local/sbin:~/bin:$PATH
Any help would be appreciated! If I missed or forgot anything please let me know, I’m quite new to this.
8
Answers
Homebrew only installs the binary
python3
, just to be safe. Xcode is complaining about a lack of the binarypython
(note the lack of a 3!).You have a couple of options:
When installing
python3
, Homebrew also creates alibexec
folder with unversioned symlinks, such aspython
(what you’re missing). Note the Caveats printed when installing it:You could add this directory to your
$PATH
, such thatpython
andpip
become available; something like the following might suffice:… although that will need to be modified according to your precise version of Python3, your shell of choice, etc.
Alternatively and more simply, although a little more jankily, you could simply manually create the appropriate symlinks:
I had posted the same question on nativescript official github and the solution that worked for me was in the answer by the user shilik
Add
-f
to be effective.This took me days of head scratching, and none of the solutions I found on the internet worked.
Eventually what DID work for me was this:
I used the find command to find all instances of python in the file hierarchy:
and I saw that there was a symbolic link labelled
python3
in/Applications/Xcode.app/Contents/Developer/usr/bin/
that was linked to a python instance deep within the bowels of Xcode.However there was no symbolic link labelled
python
which seems to be what Xcode is looking for.So I created a symbolic link linking
python
topython3
and that did the trick.For what it’s worth, I installed python via pyenv which I installed through homebrew on a 2020 Mac mini M1.
For me the problem was with missing python
env: python: No such file or directory
BUT in the end missing was python version 2.x after updating to macOS Monterey 12.5 (21G72).
Problem was resolved by installing python from:
https://www.python.org/downloads/release/python-2718/
What I’ve also tried but you probably don’t have to do:
sudo brew install python
sudo brew upgrade
sudo ln -s -f /usr/local/bin/python3 /usr/local/bin/python
sudo ln -s $(which python3) /usr/local/bin/python
sudo ln -s $(which python3) /Applications/Xcode.app/Contents/Developer/usr/bin/python
sudo ln -s /Applications/Xcode.app/Contents/Developer/usr/bin/python3 /Applications/Xcode.app/Contents/Developer/usr/bin/python
In my case, created symbolic link for dev_appserver.py like below.
Command location and version should be adapted to your environment.
I was able to solve this issue with the above-mentioned answers.
In my case, while I was trying
npm install
in my node project and was facing this issue.Note:
% brew install python
is a prerequisite for all the below steps! Test if python is correctly installed bybrew python info
What I was missing was to run
brew install python
, and it worked like a charm!