env: python: No such file or directory when building app with Xcode - TagMerge
5env: python: No such file or directory when building app with Xcodeenv: python: No such file or directory when building app with Xcode

env: python: No such file or directory when building app with Xcode

Asked 5 months ago
20
5 answers

Homebrew only installs the binary python3, just to be safe. Xcode is complaining about a lack of the binary python (note the lack of a 3!).

You have a couple of options:

  1. When installing python3, Homebrew also creates a libexec folder with unversioned symlinks, such as python (what you're missing). Note the Caveats printed when installing it:

    $ brew info python
    python@3.9: stable 3.9.10 (bottled)
    ==> Caveats
    Python has been installed as
      /opt/homebrew/bin/python3
    
    Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
    `python3`, `python3-config`, `pip3` etc., respectively, have been installed into
      /opt/homebrew/opt/python@3.9/libexec/bin
    
    See: https://docs.brew.sh/Homebrew-and-Python
    

    You could add this directory to your $PATH, such that python and pip become available; something like the following might suffice:

    echo 'export PATH="'"$(brew --prefix)"'/opt/python@3.9/libexec/bin:$PATH"' \
       >>~/.bash_profile
    

    ... although that will need to be modified according to your precise version of Python3, your shell of choice, etc.

  2. Alternatively and more simply, although a little more jankily, you could simply manually create the appropriate symlinks:

    ln -s "$(brew --prefix)/bin/python"{3,}
    

Source: link

9

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

Monterey 12.3 removes python 2. All you need to do is to reinstall python2 back to system from this link https://www.python.org/downloads/release/python-2718/

Source: link

0

  1. install python3
  2. run 'ln -s /usr/bin/python3 /usr/local/bin/python',Create a link to Python

Source: link

0

The given file does not exist and we shall see what happens if we try to execute it.
f = open('filename.txt')
Since the above text file does not exist, it will throw the IOError.
Traceback (most recent call last):
  File "main.py", line 1, in <module>
    f = open('filename.txt')
IOError: [Errno 2] No such file or directory: 'filename.txt'
Since we want to check for a file, we can use either the os.path.isfile() function or os.path.exists() function. We shall apply the function to the above example.
import os

path_name = "filename.txt"

if os.path.isfile(path_name):
  print("File exists")
  f = open(path_name)
  #Execute other file operations here
  f.close()
  
else:
  print("File does not exist! IOError has occured")
If the file does not exist, then it will print the second statement in the else condition. Unlike the previous case, here, it will not throw an error and print the message.
File does not exist! IOError has occured
It will execute the open() function only if the file exists. Thus it will not throw an error.
from pathlib import Path
path_name = "filename.txt"
p = Path(path_name)
if p.is_file():
  print("File exists")
  f = open(path_name)
  #Execute other file operations here
  f.close()
  
else:
  print("File does not exist! IOError has occured")

Source: link

0

Open Xcode and start with creating a new project: From the templates, choose Cross-platform > External Build System Give it a name. You can update Organizatin Name and Identifier if you want. Make sure you enter a correct path for Python bin. For Python 3.x it's usually
/usr/bin/pythonw
/usr/bin/pythonw
Code Block /Applications/Xcode.app/Contents/Developer/usr/bin/python3: can't open file 'hello.py': [Errno 1] Operation not permittedProgram ended with exit code: 2

Source: link

Recent Questions on python

    Programming Languages