Python – How do I run a Python script before each build of Xcode?

How do I run a Python script before each build of Xcode?… here is a solution to the problem.

How do I run a Python script before each build of Xcode?

Every time I build my application in Xcode, I try to run a simple Python script. Python scripts are called test.py and are located in my project folder as siblings to my .xcodeproj files.

I

think I followed the instructions in the Stack Overflow post
Is this possible to run a python script before Xcode doing compiling? But I get the error Shell Script Invocation Error: Command/bin/sh failed with exit code 1

I installed Python 3.5.2, but when I type python -V in the terminal, I get Python 2.7.10。 However, when I type python3 -V in the terminal, I get Python 3.6.0. Enter which python in the terminal to return /usr/bin/python, and enter which python3 in the terminal to return /Library/Frameworks/Python .framework/Versions/ 3.6/bin/python3 .

Follow the Xcode: Running a script before every build that modifies source code directly I also moved the Run Script section in Build Phases before Compile Sources.

This is what my running script part looks like. I have a strong feeling that the fix is annoyingly simple, but haven’t been successful trying to figure out what I’m doing wrong/what search terms I’m using in Google or Stack Overflow.

Run Script – Build Phases

Of course, let me know what additional information I can provide to help with debugging.

EDIT: I have no preference for which version of Python to use, other than allowing me to run Python scripts on every build. I just installed Python 3.5.2 as I thought it might help.

Edit 2: In addition to Clean (Cmd-Shift-K) and Cleaning, I tried to delete derived data (even though I was using it Xcode 8.2.1) Build Folder.... (Cmd-Shift-Alt-K) Still no luck.

Solution

I managed to implement it by using /bin/sh as my shell and python test.py as my script.

Related Problems and Solutions