Xcode 中的纯 Python
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3498839/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pure Python in Xcode
提问by Jordan
Is there a way to program using pure python in Xcode? I want something like the c++ command line utility except for python, I found a tutorialthat did not work for me: (after playing around with which active architecture finally decided on i386) when trying to print "Hello, World!"
I get the following error "Data Formatters temporarily unavailable, will re-try after a 'continue'. (Cannot call into the loader at present, it is locked.)" (Using an intel Mac OS 10.6.4 and Xcode 3.2.3)
有没有办法在 Xcode 中使用纯 python 进行编程?我想要类似 c++ 命令行实用程序的东西,除了 python,我发现了一个对我不起作用的教程:(在尝试使用哪个活动架构最终决定使用 i386 之后)当print "Hello, World!"
我尝试时出现以下错误“数据格式化程序暂时不可用, 将在“继续”后重试。(目前无法调用加载程序,它被锁定。)”(使用 intel Mac OS 10.6.4 和 Xcode 3.2.3)
Here is how I followed the steps:
1) Opened Xcode went to File -> New Project
2) Selected from 'Other', 'Empty Project'
3) Named it 'PyProject' in a local directory on my computer
4) Went to File -> New File
5) From 'Pure Python' I selected 'Python tool', named it main.py then clicked finish
6) Added print ('Hello, World!')
to the file, and saved the file
7) Went to Project -> New Custom Executable
8) Named it PyExecutable, gave it path" /Library/Frameworks/Python.framework/Versions/2.6/bin/python" and added it to project PyProject, then clicked Finish
9) Double-clicked PyExecutable in PyProject window
10) Went to Arguments and added the path of my main.py file "/Users/jordan/PyProject/main.py"
11) Switched Active Architecture from the pull down menu at the top of the PyProject window to i386 (Now is in Debug, No Active Target, PyExecutable Is Active Executable and Architecture is i386)(If I don't switch the architecture and leave it on default x86_64 I get this error as a pop-up "The active architecture x86_64 is not present in the executable 'PyExecutable' which contains ppc/i386")
12) Clicked Run -> Run and then I get the error listed above in the console
以下是我如何按照步骤操作:
1)打开 Xcode 转到文件 -> 新建项目
2)从“其他”、“空项目”中选择
3)在我计算机的本地目录中将其命名为“PyProject”
4)转到文件-> 新文件
5) 从“纯 Python”中,我选择了“Python 工具”,将其命名为 main.py,然后单击完成
6) 添加print ('Hello, World!')
到文件中,并保存文件
7) 转到项目 -> 新建自定义可执行文件
8) 命名它PyExecutable,给它路径“/Library/Frameworks/Python.framework/Versions/2.6/bin/python”并将其添加到项目PyProject,然后单击Finish
9)在PyProject窗口中双击PyExecutable
10) 转到参数并添加我的 main.py 文件“/Users/jordan/PyProject/main.py”的路径
11) 将活动架构从 PyProject 窗口顶部的下拉菜单切换到 i386(现在在Debug, No Active Target, PyExecutable Is Active Executable and Architecture is i386)(如果我不切换架构并将其保留在默认 x86_64 上,我会弹出此错误消息“可执行文件中不存在活动架构 x86_64 'PyExecutable' 包含 ppc/i386")
12) 单击 Run -> Run 然后我在控制台中得到上面列出的错误
Before anyone suggests it: I know Xcode is not the best option for pure python please do not suggest that I use another text editor.
在有人建议之前:我知道 Xcode 不是纯 Python 的最佳选择,请不要建议我使用其他文本编辑器。
Edit: details of what was not working when following the tutorial
编辑:遵循教程时不起作用的详细信息
Edit: my system details were added, and the steps I followed to get the error
编辑:添加了我的系统详细信息,以及我遵循的步骤以获取错误
Update: I wrapped the path of main.py in double quotes ""
and now when I press continue after the error the console prints hello world, but I get the same error originally.
更新:我将 main.py 的路径用双引号括起来""
,现在当我在错误后按继续时,控制台会打印 hello world,但我最初遇到了相同的错误。
采纳答案by Ned Deily
/Library/Frameworks/Python.framework/Versions/2.6/bin/python
is typically the path to the python.org installer Python (or possibly other non-Apple Python) which, indeed, includes only 32-bit architectures (ppc
and i386
). It also is built using the OS X 10.4u SDK (an optional install with Xcode on 10.6). The Apple-supplied Python 2.6 in 10.6 is built using a 10.6 SDK and includes 32-bit and 64-bit archs (i386
, x86_64
, and ppc
for compatibility).
/Library/Frameworks/Python.framework/Versions/2.6/bin/python
通常是 python.org 安装程序 Python(或可能其他非 Apple Python)的路径,它实际上只包含 32 位架构(ppc
和i386
)。它还使用 OS X 10.4u SDK(10.6 上的 Xcode 可选安装)构建。苹果提供的在10.6 Python 2.6中是使用10.6 SDK构建,并且包括32位和64位archs( ,i386
,x86_64
和ppc
兼容性)。
$ /usr/local/bin/python2.6 -c 'import sys;print(sys.executable)' # python.org Python
/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python
$ /usr/bin/python2.6 -c 'import sys;print(sys.executable)' # Apple-supplied Python
/usr/bin/python2.6
Decide which Python you want to use and change your Xcode project accordingly.
决定您要使用哪个 Python 并相应地更改您的 Xcode 项目。