前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >在 Xcode 9 中搭建 Python

在 Xcode 9 中搭建 Python

作者头像
py3study
发布2020-01-09 09:50:33
1.7K0
发布2020-01-09 09:50:33
举报
文章被收录于专栏:python3python3python3

环境依赖

macOS、Xcode 9、Python(macOS 默认安装了 Python2.7)。

The first stepThe first stepThe\ first\ step:创建工程

首先,新建一个 External Build SystemExternal Build SystemExternal\ Build\ System,如图:

这里写图片描述
这里写图片描述

然后注意在 Build ToolBuild ToolBuild\ Tool 一栏填入 PythonPythonPython 的路径,这里我填入的是 /usr/bin/python/usr/bin/python/usr/bin/python,如图:

这里写图片描述
这里写图片描述

如果本地 PythonPythonPython 路径不是这个,可以通过在命令行输入 which pythonwhich pythonwhich\ python 来查找。

其他的和平时创建工程无异,填写必要的信息,修改路径就 OKOKOK 了。

The second stepThe second stepThe\ second\ step:编辑 SchemeSchemeScheme

接下来我们需要编辑一下 SchemeSchemeScheme,如图点击 Edit Scheme...Edit Scheme...Edit\ Scheme... 打开编辑界面:

这里写图片描述
这里写图片描述

默认是在 Run−ArgumentsRun−ArgumentsRun-Arguments 界面,我们需要进入 Run−InfoRun−InfoRun-Info 界面修改 ExecutableExecutableExecutable(可执行文件),选择 OtherOtherOther,如图:

这里写图片描述
这里写图片描述

此时会弹出路径窗口,直接在键盘输入 "/""/""/" (不加引号)会弹出输入路径窗口,输入前边我们设置的路径,我的是 /usr/bin//usr/bin//usr/bin/,如图:

这里写图片描述
这里写图片描述

点击 GoGoGo 后会让选择,选择可执行文件 pythonpythonpython,默认 DebugexecutableDebugexecutableDebug executable 为勾选,取消勾选。

接着进入 Run−ArgumentsRun−ArgumentsRun-Arguments 界面,点击 Arguments Passed On LaunchArguments Passed On LaunchArguments\ Passed\ On\ Launch 一栏中的 "+""+""+",新增接下来要用到的文件名。

这里写图片描述
这里写图片描述

然后进入 Run−OptionsRun−OptionsRun-Options 界面,添加 WorkingDirectoryWorkingDirectoryWorking Directory,这里我设置的是刚才创建工程的目录,用相对目录应该也是可以的,这里我用的是绝对目录。

这里写图片描述
这里写图片描述

此时完成了设置,可以 CloseCloseClose 了。

The third partThe third partThe\ third\ part:新建 Py 文件并测试

新建一个 EmptyEmptyEmpty 文件,命名为 Test.pyTest.pyTest.py,如图:

这里写图片描述
这里写图片描述

写入测试代码 print("Hello World")print("Hello World")print("Hello\ World"),顺利的话会输出 Hello WorldHello WorldHello\ World,然而……

这里写图片描述
这里写图片描述

并不顺利,pythonpythonpython 告诉我们不能找到这个文件……

其实这个也很容易理解,从图上看可以发现我没有直接在工程根目录下创建 Test.pyTest.pyTest.py,而是先 Now GroupNow GroupNow\ Group 了一个 TestTestTest,所以导致找不到 Test.pyTest.pyTest.py 文件。

解决方案也很简单,就是进入我们刚才设置的 Run−ArgumentsRun−ArgumentsRun-Arguments 界面,点击 Arguments Passed On LaunchArguments Passed On LaunchArguments\ Passed\ On\ Launch 下的 "+""+""+" 添加文件时,和我们创建的这个文件路径一定要保持一致,如图:

这里写图片描述
这里写图片描述

重新 Command+RCommand+RCommand + R,运行正常,输出 Hello WorldHello WorldHello\ World,搭建完毕。

这里写图片描述
这里写图片描述
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-09-06 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 环境依赖
  • The first stepThe first stepThe\ first\ step:创建工程
  • The second stepThe second stepThe\ second\ step:编辑 SchemeSchemeScheme
  • The third partThe third partThe\ third\ part:新建 Py 文件并测试
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档