Xcode 4+ 中的 Python? [英] Python in Xcode 4+?

查看:54
本文介绍了Xcode 4+ 中的 Python?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Xcode 4、5、6 或 7 中创建一个 Python 友好的环境?

How does one create a Python friendly environment in Xcode 4, 5, 6 or 7?

推荐答案

我想通了!这些步骤看起来比实际需要更多的努力.

I figured it out! The steps make it look like it will take more effort than it actually does.

这些说明用于从头开始创建项目.如果您希望在此项目中包含现有的 Python 脚本,您显然需要稍微偏离这些说明.

These instructions are for creating a project from scratch. If you have existing Python scripts that you wish to include in this project, you will obviously need to slightly deviate from these instructions.

如果您发现这些说明由于 Xcode 更新的变化而不再有效或不清楚,请告诉我.我会进行必要的更正.

If you find that these instructions no longer work or are unclear due to changes in Xcode updates, please let me know. I will make the necessary corrections.

  1. 打开 Xcode.两者的说明相同.
  2. 在菜单栏中,单击文件"→新建"→新建项目...".
  3. 在左侧窗格中选择其他",然后在右侧页面中选择外部构建系统",然后单击下一步".
  4. 输入产品名称、组织名称或组织标识符.
  5. 对于构建工具"字段,输入 /usr/local/bin/python3(对于 Python 3)或 /usr/bin/python(对于 Python 2),然后点击下一步".请注意,这假设您具有解析为 Python 可执行文件的符号链接(默认设置).如果您不确定 Python 可执行文件的位置,请在终端中输入以下任一命令:which python3which python.
  6. 点击下一步".
  7. 选择保存位置并点击创建".
  8. 在菜单栏中,单击文件"→新建"→新建文件...".
  9. 在OS X"下选择其他".
  10. 选择Empty"并点击Next".
  11. 导航到项目文件夹(否则将不起作用),输入 Python 文件的名称(包括.py"扩展名),然后单击创建".
  12. 在菜单栏中,单击产品"→方案"→编辑方案...".
  13. 点击左侧窗格中的运行".
  14. 在信息"选项卡中,单击可执行文件"字段,然后单击其他...".
  15. 导航到第 5 步中的可执行文件.如果目录处于隐藏状态,您可能需要使用 ⇧⌘G 输入该目录.
  16. 选择可执行文件并点击选择".
  17. 取消选中调试可执行文件".如果跳过这一步,Xcode 将尝试调试 Python 可执行文件本身.我不知道将外部调试工具集成到 Xcode 中的方法.
  18. 点击启动时传递的参数"下的+"图标.您可能需要点击指向右侧的三角形来展开该部分.
  19. 输入 $(SRCROOT)/(或 $(SOURCE_ROOT)/),然后输入要测试的 Python 文件的名称.请记住,Python 程序必须在项目文件夹中.否则,您必须在此处输入完整路径(或相对路径,如果它位于项目文件夹的子文件夹中).如果完整路径中的任意位置有空格,则必须在其开头和结尾处加上引号.
  20. 点击关闭".
  1. Open Xcode. The instructions for either are the same.
  2. In the menu bar, click "File" → "New" → "New Project…".
  3. Select "Other" in the left pane, then "External Build System" in the right page, and next click "Next".
  4. Enter the product name, organization name, or organization identifier.
  5. For the "Build Tool" field, type in /usr/local/bin/python3 for Python 3 or /usr/bin/python for Python 2 and then click "Next". Note that this assumes you have the symbolic link (that is setup by default) that resolves to the Python executable. If you are unsure as to where your Python executables are, enter either of these commands into Terminal: which python3 and which python.
  6. Click "Next".
  7. Choose where to save it and click "Create".
  8. In the menu bar, click "File" → "New" → "New File…".
  9. Select "Other" under "OS X".
  10. Select "Empty" and click "Next".
  11. Navigate to the project folder (it will not work, otherwise), enter the name of the Python file (including the ".py" extension), and click "Create".
  12. In the menu bar, click "Product" → "Scheme" → "Edit Scheme…".
  13. Click "Run" in the left pane.
  14. In the "Info" tab, click the "Executable" field and then click "Other…".
  15. Navigate to the executable from Step 5. You might need to use ⇧⌘G to type in the directory if it is hidden.
  16. Select the executable and click "Choose".
  17. Uncheck "Debug executable". If you skip this step, Xcode will try to debug the Python executable itself. I am unaware of a way to integrate an external debugging tool into Xcode.
  18. Click the "+" icon under "Arguments Passed On Launch". You might have to expand that section by clicking on the triangle pointing to the right.
  19. Type in $(SRCROOT)/ (or $(SOURCE_ROOT)/) and then the name of the Python file you want to test. Remember, the Python program must be in the project folder. Otherwise, you will have to type out the full path (or relative path if it's in a subfolder of the project folder) here. If there are spaces anywhere in the full path, you must include quotation marks at the beginning and end of this.
  20. Click "Close".

请注意,如果您打开实用工具"面板,并且显示文件检查器"选项卡处于活动状态,则文件类型会自动设置为默认 - Python 脚本".随意查看它具有的所有文件类型选项,以了解它的所有功能.上述方法可以应用于任何解释性语言.到目前为止,我还没有弄清楚如何让它与 Java 一起工作.话又说回来,我还没有做太多研究.当然,网络上有一些关于所有这些的文档.

Note that if you open the "Utilities" panel, with the "Show the File inspector" tab active, the file type is automatically set to "Default - Python script". Feel free to look through all the file type options it has, to gain an idea as to what all it is capable of doing. The method above can be applied to any interpreted language. As of right now, I have yet to figure out exactly how to get it to work with Java; then again, I haven't done too much research. Surely there is some documentation floating around on the web about all of this.

如果您没有管理权限或不在开发人员组中,您仍然可以使用 Xcode 进行 Python 编程(但您仍然无法使用需要编译的语言进行开发).不使用播放按钮,而是在菜单栏中单击产品"→执行操作"→无需构建即可运行"或只需使用键盘快捷键 ^⌘R.

If you do not have administrative privileges or are not in the Developer group, you can still use Xcode for Python programming (but you still won't be able to develop in languages that require compiling). Instead of using the play button, in the menu bar, click "Product" → "Perform Action" → "Run Without Building" or simply use the keyboard shortcut ^⌘R.

要更改文本编码、行尾和/或缩进设置,请打开实用工具"面板并单击显示文件检查器"选项卡处于活动状态.在那里,您会找到这些设置.

To change the text encoding, line endings, and/or indentation settings, open the "Utilities" panel and click "Show the File inspector" tab active. There, you will find these settings.

有关 Xcode 构建设置的更多信息,没有比 这个.我很想听听谁让这个与不受支持的编译语言一起工作的人的意见.这个过程应该适用于任何其他解释性语言.请务必相应地更改第 5 步和第 16 步.

For more information about Xcode's build settings, there is no better source than this. I'd be interested in hearing from somebody who got this to work with unsupported compiled languages. This process should work for any other interpreted language. Just be sure to change Step 5 and Step 16 accordingly.

这篇关于Xcode 4+ 中的 Python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆