理解在Mac OS上用于Cocoa开发的Python安装概念

0 投票
1 回答
883 浏览
提问于 2025-04-16 14:03

我想尝试用Python开发Cocoa应用程序。我对Mac还很陌生,需要一些帮助来理解它是怎么工作的。

首先,我发现需要安装py2app和py2objc。我按照文档中的说明使用了easy_install,具体可以在这里找到。安装过程中遇到了一些setup tools的错误,但最终还是安装上了py2app。然后我运行了"easy_install pyobjc==2.2",结果出现了很多错误:

Processing pyobjc-2.2-py2.7.egg
    ...
Running pyobjc-framework-SystemConfiguration-2.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-ipMzFU/pyobjc-framework-SystemConfiguration-2.2/egg-dist-tmp-odfVol
    In file included from Modules/_manual.m:1:
    /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:19:20: error: limits.h: No such file or directory
    /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:22:2: error: #error "Something's broken.  UCHAR_MAX should be defined in limits.h."
    /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:26:2: error: #error "Python's source code assumes C's unsigned char is an 8-bit type."
    /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:33:19: error: stdio.h: No such file or directory
    /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:35:5: error: #error "Python.h requires that stdio.h define NULL."
    /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:38:20: error: string.h: No such file or directory
    /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:40:19: error: errno.h: No such file or directory
    /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:42:20: error: stdlib.h: No such file or directory
    /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:44:20: error: unistd.h: No such file or directory
    /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:56:20: error: assert.h: No such file or directory
...
etc

我有几个问题:

  1. 我该怎么安装py2objc?很遗憾,我还没找到解决之前错误的方法。
  2. 我了解到有两种Python。一种是我安装在应用程序文件夹里的(IDLE,启动器),另一种是操作系统自带的当前Python版本。你能解释一下它们的区别吗?
  3. 我怎么选择Mac OS使用的当前Python版本?/Library/Frameworks/Python.framework里的Current文件夹是什么?

可能看起来有点混乱,但这只是我刚开始的步骤! :) 谢谢你

1 个回答

1
  1. 这个问题没有明确的答案。请看评论。
  2. 你可以在你的电脑上安装多个版本的Python(OSX自带一个默认版本,正如你提到的)。在应用程序文件夹里,有一些可以打开交互式解释器的应用程序,你可以在里面输入Python命令,比如IDLE。这些应用程序会使用你已经安装的某个Python版本。这就引出了下面的内容。
  3. python_select是你需要使用的命令。例如,使用python_select -l可以列出你安装的所有Python版本,而python_select python27可以选择你自己的2.7版本。Current文件夹链接到当前通过python_select选择的版本。

撰写回答