查看Python版本
$ python -V
Python 3.5.1
【我这里以Python3.5.1为例,系统自带的是2.x,如果自己需要安装3.x】安装方法:参考前面几篇博客
http://my.oschina.net/u/868062/blog/631185
http://my.oschina.net/u/868062/blog/632555
http://my.oschina.net/u/868062/blog/631173
在Xcode下编写运行Python文件
Xcode 环境配置
打开Xcode,选择File > New > New Project,或按下Shift + Command + N,然后选择最下面的Other其它选项卡,并选择[External Build System],继续下一步
![](https://img.haomeiwen.com/i5544444/3e38b2182013449e.png)
![](https://img.haomeiwen.com/i5544444/3fd13e7dab8bab70.png)
完成后,在左上角的项目图表上点击一下,选择[Edit Scheme]
![](https://img.haomeiwen.com/i5544444/f50ef47b9204bd24.png)
默认配置如下
![](https://img.haomeiwen.com/i5544444/643a4f48dd216106.png)
修改配置【executable】可执行文件 其他的默认即可
![](https://img.haomeiwen.com/i5544444/ab4c9e869736fca7.png)
![](https://img.haomeiwen.com/i5544444/5243bccad7a14036.png)
配置好了,接下来创建一个python文件,抒写代码
在项目中New-->File-->Other-Empty创建一个空文件 命名为main.py
![](https://img.haomeiwen.com/i5544444/87564b4457353edd.png)
![](https://img.haomeiwen.com/i5544444/1ebadcc56aec55aa.png)
接下来再次Edit Schem-->Arguments把main.py添加的文件添加到Arguments Passed On Launch
![](https://img.haomeiwen.com/i5544444/3d46b48a3aa08374.png)
再配置一下Options-->Working Directory选择文件坐在目录我这里(/Users/apple/Desktop/pythonTest)
![](https://img.haomeiwen.com/i5544444/ec2a1597176abce9.png)
接下来抒写代码 运行
print('hello Python')
Run
![](https://img.haomeiwen.com/i5544444/2c2e728e67b65d69.png)
在终端直接执行Python文件
打开终端cd到Python文件目录(也可直接把Python文件拖拽到终端)
![](https://img.haomeiwen.com/i5544444/21ca383294155d2e.png)
直接运行文件
$ Python main.py
报错
File "main.py", line 2
print 'hello Python'
^
SyntaxError: Missing parentheses in call to 'print'
python3取消了这种用法。使用print('hello Python")或print('hello python')
改一下代码 继续执行
print('hello Python')
$ Python main.py
![](https://img.haomeiwen.com/i5544444/580aff4bf683da10.png)
网友评论