简体   繁体   English

为什么使用gcc-4.0构建python.org OS X安装程序?

[英]Why are the python.org OS X installers built with gcc-4.0?

In answering SO question 3500638 , Ned Deily states that the Apple-supplied Pythons (2.5.4 and 2.6.5) are both built with gcc-4.2. 在回答问题3500638时 ,Ned Deily表示Apple提供的Pythons(2.5.4和2.6.5)都是用gcc-4.2构建的。 However, all three of the python.org OS X Pythons (2.6.5, 2.7, 3.1.2) are built using gcc-4.0. 但是,所有三个python.org OS X Pythons( 2.6.5,2.7,3.1.2 )都是使用gcc-4.0构建的。

Questions 问题

  1. Why are the python.org Pythons (2.6.5, 2.7, 3.1.2) built using gcc-4.0? 为什么使用gcc-4.0构建python.org Pythons( 2.6.5,2.7,3.1.2 )?
  2. What are the gotchas of using one of the python.org Pythons built with gcc-4.0? 使用gcc-4.0构建的python.org pythons之一有什么问题?

As for the second question, I find myself issuing one or more of the following commands prior to building Python extensions: 至于第二个问题,我发现自己在构建Python扩展之前发出了以下一个或多个命令:

export CC=/usr/bin/gcc-4.0
export CPP=/usr/bin/cpp-4.0
export CXX=/usr/bin/g++-4.0

这可能与苹果提供的OS X 10.5的 Python(2.5.1)是用gcc-4.0构建的事实有关 - 毕竟,python.org的DMG支持OS X 10.5 10.6(不确定它们是否相同)也支持旧版本的操作系统)。

  1. For some time now, the python.org OS X installers have been built with the requirement to provide one Python executable and shared library that will work on all recent OS X releases that support PPC and Intel processors. 一段时间以来,python.org OS X安装程序的构建需要提供一个Python可执行文件和共享库,这些库可以在支持PPC和Intel处理器的所有最新OS X版本上运行。 A separate but closely related requirement is that it must be possible for end users to be able to build and install Python packages with C or C++ extension modules. 一个单独但密切相关的要求是,最终用户必须能够使用C或C ++扩展模块构建和安装Python包。 Yet another goal is to make it easy, with the help of tools like py2app , to build and package full-fledged standalone OS X applications that can work out of the box on multiple OS releases. 另一个目标是借助py2app等工具py2app构建和打包成熟的独立OS X应用程序,这些应用程序可以在多个操作系统版本上开箱即用。 For various reasons, gcc-4.0 on OS X is currently the one version that meets all of those requirements. 由于各种原因,OS X上的gcc-4.0目前是满足所有这些要求的一个版本。 But the choice of ABI deployment target, build architectures, and OS X SDKs are important issues as well. 但是ABI部署目标,构建体​​系结构和OS X SDK的选择也是重要的问题。 Choosing a build environment that allows Python (the traditional cPython) itself to be built on any supported platform also helps to ensure that C extension modules can be built on any of those platforms. 选择允许在任何支持的平台上构建Python(传统的cPython)本身的构建环境也有助于确保可以在任何这些平台上构建C扩展模块。

    The gory details: gcc-4.0 remains the most recent gcc version supplied in the last Developer Tools releases for 10.4. 血腥细节:gcc-4.0仍然是最新的10.4版开发人员工具版本中提供的最新gcc版本。 The 10.5 and 10.6 Developer Tools supply both 4.0 and 4.2 but 4.0 is still the default for 10.5. 10.5和10.6开发人员工具同时提供4.0和4.2,但4.0仍然是10.5的默认值。 Thus, gcc-4.0 is the common denominator for the three most recent OS X releases. 因此,gcc-4.0是最新的三个OS X版本的共同点。 Beyond the gcc version itself, there is also the question of which ABI to build for, ie what OS X calls deployment target . 除了gcc版本本身之外,还有一个问题是要构建哪个ABI,即OS X称之为部署目标 Generally, OS X goes to some pains to ensure backwards compatibility, allowing older binaries to work on newer systems even though most are dynamically linked. 通常,OS X会尽一切努力确保向后兼容性,允许较旧的二进制文件在较新的系统上工作,即使大多数动态链接也是如此。 So to be able to build a Python interpreter that will work on 10.4 through 10.6, you would use gcc-4.0, set MACOSX_DEPLOYMENT_TARGET to 10.4 (the minimum OS X level needed to run), use the corresponding SDK for 10.4 (it's somewhat confusingly called 10.4u , as in universal , and is an optional install for the 10.6 versions of the Xcode Developer Tools), and set the universal architectures to i386 and ppc , the only two that are fully supported at run time on all of those systems. 因此,为了能够构建一个可以在10.4到10.6上工作的Python解释器,你可以使用gcc-4.0,将MACOSX_DEPLOYMENT_TARGET设置为10.4(运行所需的最低OS X级别),使用10.4的相应SDK(它有点令人困惑地称为10.4u ,与universal ,是Xcode开发人员工具的10.6版本的可选安装),并将通用架构设置为i386ppc ,这是在所有这些系统上运行时完全支持的唯一两个。

    The OS X installer builds cheat a little bit and go one step step further: they actually set the deployment target to 10.3 which, it turns out, results in a binary that will work with all OS X releases, from 10.6 back to OS X 10.3.9, the final 10.3 release, although not with early 10.3 releases. OS X安装程序稍微构建了一些欺骗行为并更进了一步:它们实际上将部署目标设置为10.3,结果表明,这将导致二进制文件适用于所有OS X版本,从10.6回到OS X 10.3 .9,最终的10.3版本,虽然不是早期的10.3版本。 (Note, if you are still using 10.3.9, since gcc-4.0 is not included with the 10.3 Developer Tools, manual intervention will likely be needed to build C extension modules there, such as overriding the gcc version, and you may run into other problems. Python on 10.3.9 gets minimal testing and exposure as part of the python.org release process these days so user beware.) (注意,如果您仍在使用10.3.9,因为10.3开发人员工具中不包含gcc-4.0,可能需要手动干预以在那里构建C扩展模块,例如覆盖gcc版本,并且您可能遇到其他问题。目前10.3.9上的Python作为python.org发布过程的一部分获得了最少的测试和曝光,因此用户要小心。)

  2. Gotchas : the most important should be clear from the above. 陷阱 :最重要的应该从上面清楚。 When building or installing packages with extension modules, ensure that you are using a compatible GCC version, architectures, deployment target, and SDK. 在使用扩展模块构建或安装软件包时,请确保使用兼容的GCC版本,体系结构,部署目标和SDK。 Fortunately, if the package uses Python's Distutils to build and install the extension module, generally all of this will be taken care of for you automatically as Distutils uses saved values based on the Python interpreter's build environment. 幸运的是,如果软件包使用Python的Distutils来构建和安装扩展模块,通常所有这些都将自动处理,因为Distutils使用基于Python解释器构建环境的保存值。 That covers just about every Python package that comes with a setup.py install script and applies to higher-level install tools that use Distutils under the covers, things like easy_install and pip . 这几乎涵盖了setup.py安装脚本附带的每个Python包,并适用于使用Distutils更高级别的安装工具,例如easy_installpip

    An important exception: the automatic setting by Distutils of GCC to gcc-4.0 is something that was added after the release of 10.6 made it an issue so it is not done in earlier releases of 2.6 or 3.1 and not at all in 2.5. 一个重要的例外:由GCC的Distutils自动设置为gcc-4.0是在10.6发布之后添加的一个问题,因此它不是在早期版本的2.6或3.1中完成的,而在2.5中完全没有。 When in doubt, you can always set and export it manually as shown in your question. 如有疑问,您可以随时设置并手动导出,如问题所示。

    Another common gotcha when building or installing extension modules comes up when the module uses other 3rd-party libraries or binaries. 当模块使用其他第三方库或二进制文件时,会出现构建或安装扩展模块时的另一个常见问题。 Those must also be compatible. 那些也必须兼容。 In particular, for 10.6 the system default is to build, link, and execute as Intel-64 ( -arch x86_64 ) where possible. 特别是,对于10.6,系统默认是在可能的情况下以Intel-64( -arch x86_64 )构建,链接和执行。 This can result in the problem that 3rd-party non-Python libraries you install can't be statically or dynamically linked with the Python extension module because there is no compatible common architecture (since the python.org Python includes only the 32-bit i386 and ppc archs). 这可能导致您安装的第三方非Python库无法与Python扩展模块静态或动态链接的问题,因为没有兼容的通用体系结构(因为python.org Python仅包含32位i386ppc archs)。 To get around this, you need to be careful to force the right universal architectures when building the 3rd-party libraries. 要解决这个问题,在构建第三方库时需要小心强制使用正确的通用体系结构。 How easy it is to do that varies greatly among various libraries. 这样做有多容易,各个库之间差异很大。 The plan is for the next releases of Python 2.7 and Python 3.2 to include a second 32-bit/64-bit Intel-only universal installer option built for 10.6 and above that should make life much easier on 64-bit systems. 该计划适用于Python 2.7和Python 3.2的下一个版本,包括为10.6及更高版本构建的第二个32位/ 64位仅限Intel的通用安装程序选项,可以使64位系统的生活更加轻松。 (Note, for the initial release of 2.7 there is a second 32-bit/64-bit installer except that it was built for 10.5 and above and includes 32-bit ppc as well. Unfortunately, that configuration turns out to have a number of problems, including IDLE and Tkinter not working on 10.6. I would use it only with caution.) (注意,对于2.7的初始版本,有第二个32位/ 64位安装程序,除了它是为10.5及更高版本构建的,并且还包括32位ppc。不幸的是,该配置结果是问题,包括IDLETkinter在10.6上没有工作。我会谨慎使用它。)

    For many popular Python packages with 3rd-party library dependencies ( PIL and MySQLdb come to mind), there is another approach to minimizing compatibility problems and that it is to use a complete solution (Python, Python packages, and 3rd-party libraries) from one of the third-party open source package distributors for OS X, such as MacPorts, Homebrew, or Fink. 对于许多流行的具有第三方库依赖关系的Python包( PILMySQLdb可以想到),还有另一种方法可以最大限度地减少兼容性问题,并且可以使用完整的解决方案(Python,Python包和第三方库)。 OS X的第三方开源软件包分销商之一,如MacPorts,Homebrew或Fink。 There are some pitfalls getting started with each but, in the long run, their use can often save a lot of headaches. 每一个都有一些陷阱开始,但从长远来看,它们的使用通常可以避免很多麻烦。

    Obviously another gotcha would be trying to build a package that depends on a new feature or bug fix not found in Apple's gcc-4.0 releases. 显然,另一个问题是尝试构建一个依赖于Apple的gcc-4.0版本中没有的新功能或错误修复的软件包。 I am not aware of any such packages but there could be some. 我不知道任何这样的包,但可能有一些。 If so, that might be another good reason to go with another Python solution, such as building and installing Python from MacPorts. 如果是这样,这可能是另一个使用其他Python解决方案的好理由,例如从MacPorts构建和安装Python。

According to Python issue 6957 : 根据Python问题6957

Recent python.org installers are built using the OS X 10.4 SDK so that one installer image will work on 10.4, 10.5 and now 10.6 (in theory, 10.3.x as well). 最近的python.org安装程序是使用OS X 10.4 SDK构建的,因此一个安装程序映像可以在10.4,10.5和现在10.6(理论上也是10.3.x)上运行。

While this answers why the python.org Pythons use gcc-4.0, I'd still be interested in knowing if there are any gotchas beyond having to set gcc-4.0 when building Python extensions. 虽然这解释了为什么python.org Pythons使用gcc-4.0,但我仍然有兴趣知道在构建Python扩展时是否还有任何问题需要设置gcc-4.0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM