Building and Running Python Scripts with Xcode

Hi,

If you want to run python file from xcode, you can follow this link which I have followed.

 https://medium.com/sourleangchhean/using-xcode-to-execute-pythons-code-98be65c1ea8a


Here is few steps which I have done.

  •  Download and install python (If not already downloaded)(I have downloaded 3.9 version)
  • Check if it available in at /usr/local/bin/python3
  • Right Click on Python3 then select Show Original
  • Get in to that location in terminal. (Open terminal type cd and drag drop that location file)
    • in my case path is "cd /Library/Frameworks/Python.framework/Versions/3.9/bin/"
  •  Type "ln python3.9 python39"
  • This is for terminal part.
Now create new xcode project 
File > New > Project > Cross-platform > External Build System > Next
Enter Name and 
  • Enter a name (e.g. PythonLearning), and enter the path from  above Step(i.e /usr/local/bin/python3) into the “Build Tool” line. Click Next.
  •  Create a Python file

    • Choose File > New, select macOS > Other > Empty. Click Next.
    • Save it by name "helloWorld.py"

    Step 5. Edit your Run Scheme


    • Click and hold on the PythonLearning target in the jump bar. Select Edit Scheme…
    • Info -> executable -> Other
    • Dialog box will appear, now 
    • Drag "python39" to Choose an executable to launch dialog box.

    Step 7. Add Launch Arguments

    Now, click the Arguments tab. Click + under “Arguments Passed On Launch” and type helloWorld.py 

    Step 8: Now click the Options tab. Click + under “Arguments Passed On Launch”
    go to "Working directory" , select it and choose the path of your current project.
    Done.
    Run now .

Comments

Popular posts from this blog

Launch iPhone simulator without Xcode.

How to Make REST api call in Objective-C.

id vs NSObject