使⽤Xcode编写并运⾏Python
1.到Python位置:
终端输⼊:which python
获取python的安装位置,⼀般为/usr/bin/python。获取到这个路径⽅便使⽤它来搭建python的编译环境。
2.在Xcode中创建python程序
python能在手机上运行吗打开Xcode,新建⼯程(Shift+Command+N),选择Cross-platform->Ohter->External Build System,继续下⼀步
在Build Tool中粘贴刚刚到的python路径,eg:/usr/bin/python,点击Next:
3.设置Edit Scheme
创建好项⽬之后,在左上⾓的项⽬图表上点击⼀下,选择Edit Scheme
第⼀个选项Info中的Executable选择python的路径,eg:/usr/bin/python
第⼆个选项Arguments⾥,在第⼀个Arguments passed on launch⾥,新建⼀个你即将新建的.py⽂件,eg:main.py
第三个选项Option⾥,勾选Working Directory并选择到Xcode Project所在的⽂件夹,也就是你的.py⽂件存放的⽂件夹,最后选择确定。
3.Build and Run
在项⽬中新建⽂件(Command+N),选择macOS->Other->Empty,命名为刚刚在Scheme⾥添加的⽂件名,eg:mian.py
现在编写代码,并点击Run,就可以实现python程序在Xcode下的编译和运⾏了。