如何在Xcode中每次构建前运行Python脚本?

3

我试图在每次在Xcode中构建我的应用程序时运行一个简单的Python脚本。Python脚本名为test.py,与我的.xcodeproj文件同级,都位于我的项目文件夹中。

我认为我遵循了Stack Overflow帖子Is this possible to run a python script before Xcode doing compiling?中的说明,但是我收到了错误信息Shell Script Invocation Error: Command /bin/sh failed with exit code 1

我安装了Python 3.5.2,但是当我在终端中输入python -V时,返回结果是Python 2.7.10。然而,当我在终端中输入python3 -V时,返回结果是Python 3.6.0。在终端中输入which python返回/usr/bin/python,而在终端中输入which python3返回/Library/Frameworks/Python.framework/Versions/3.6/bin/python3

按照Xcode: Running a script before every build that modifies source code directly中的说明,我将运行脚本部分移动到Compile Sources之前的Build Phases。

这是我的运行脚本部分的样子。我强烈感觉修复方法非常简单,但一直无法找出我做错了什么/在Google或Stack Overflow中使用什么搜索词。

Run Script – Build Phases

当然,请告诉我需要提供哪些其他信息以帮助调试。
编辑:除了它允许我每次构建时运行Python脚本之外,我对使用哪个版本的Python没有偏好。我刚安装了Python 3.5.2因为我认为这可能有所帮助。
编辑2:尝试删除派生数据(即使我正在使用Xcode 8.2.1),以及清理(Cmd-Shift-K)和清理构建文件夹...(Cmd-Shift-Alt-K),但仍然没有运气。

如果你想使用Python3.5,需要在命令行中运行python3.5,而不是运行带有最新版本的Python 3(在你的安装中为Python 3.6.0)的python3 - Laurent LAPORTE
2个回答

3

我成功地使用 /bin/sh 作为我的 shell,python test.py 作为我的脚本。


0
在“Shell”输入中,尝试使用以下路径:'/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5'。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接