View Python version
$ python -V
[I take Python3.5.1 as an example, the system comes with 2.x, if you need to install 3.x] Installation method: refer to the previous blogs
Python 3.5.1
Write and run Python files under Xcode
Xcode environment configuration
Open Xcode , selectFile > New > New Project , or press Shift + Command + N , then select the Other tab at the bottom , and select [ External Build System ] to continue to the next step
When done, click once on the project chart in the upper left corner and select [ Edit Scheme ]
The default configuration is as follows
Modify the configuration [ executable ] other default executable files
Once configured, create a python file and write the code
Create an empty file named main.py in New-->File-->Other-Empty in the project
Next, Edit Schem--> Arguments add the file added by main.py to Arguments Passed On Launch
Configure again Options-->Working Directory Select the file to sit in the directory I am here (/ Users/apple/Desktop/pythonTest)
Next, write the code to run
print ('hello Python')
Run
Open the terminal and cd to the Python file directory (you can also drag and drop the Python file directly to the terminal)
run the file directly
$ Python main.py
report an error
File "main.py", line 2
print 'hello Python'
^
SyntaxError: Missing parentheses in call to 'print'
python3 does away with this usage. Use print('hello Python") or print('hello python')
Change the code to continue execution
print ('hello Python')
$ Python main.py
Execute Python files directly in the terminal