简体   繁体   English

如何使Python和distutils在Mac OS X上使用正确的SDK?

[英]How to make Python and distutils use the right SDK on Mac OS X?

I use Python on Mac OS X version 10.6. 我在Mac OS X 10.6版上使用Python。 I recently installed the newest Mac OS X developer tools SDK, which has GCC in it. 我最近安装了最新的Mac OS X开发人员工具SDK,其中包含GCC。 The SDKs I have are: 我拥有的SDK是:

$ ls /Developer/SDKs/
MacOSX10.4u.sdk MacOSX10.5.sdk  MacOSX10.6.sdk

I'd like to use Mac OS X 10.6 with Python/distutils, whenever I install a python package with "setup.py install" that requires compilation. 每当我通过“ setup.py install”安装需要编译的python软件包时,就想将Mac OS X 10.6与Python / distutils一起使用。

I notice that Python passes the -isysroot flags and paths to Mac OS X 10.5 (not 10.6), ie: 我注意到Python将-isysroot标志和路径传递到Mac OS X 10.5 (不是10.6),即:

$ python-config --cflags --ldflags
-I/Library/Frameworks/EPD64.framework/Versions/7.0/include/python2.7 -I/Library/Frameworks/EPD64.framework/Versions/7.0/include/python2.7 -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.5.sdk -DNDEBUG -g -O3 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.5.sdk -I/Library/Frameworks/EPD64.framework/Versions/7.0/include
-L/Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/config -ldl -framework CoreFoundation -lpython2.7 EPD64.framework/Versions/7.0/Python

How can I correct this? 我该如何纠正? I'd like it to use the 10.6 SDK instead. 我希望它改用10.6 SDK。

Right now when I run "python setup.py install" on a package that requires C compilation, it yields calls to GCC that look like this: 现在,当我在需要C编译的软件包上运行“ python setup.py install”时,它会产生对GCC的调用,如下所示:

gcc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.5.sdk -DNDEBUG -g -O3 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.5.sdk -I/Library/Frameworks/EPD64.framework/Versions/7.0/include -DHAVE_RINTF=1 -DHAVE_FINITE=1 -DHAVE_EXPM1=1 -DHAVE_RINT=1 -DHAVE_LOG2=1 -DHAVE_LOGBL=1 -DHAVE_SNPRINTF=1 -DHAVE_LOG1P=1 -DHAVE_ROUND=1 -DHAVE_FMIN=1 -Iinclude -Isrc/lapack -Isrc/f2c -I/Library/Frameworks/EPD64.framework/Versions/7.0/include/python2.7 -c src/f2c/signal_.c -o build/temp.macosx-10.5-x86_64-2.7/src/f2c/signal_.o

which calls 10.5 SDKs in its path. 它在其路径中调用10.5 SDK。

I use the Enthought Python Distribution installation of Python in case that makes a difference. 我使用了Python的Enthought Python Distribution安装,以防万一。

Thanks very much. 非常感谢。

It's a feature and should not cause you any worries. 这是一项功能,不会给您带来任何麻烦。 Distutils does this deliberately to ensure that C extension modules that you build are built the same way that the Python interpreter in use was built. Distutils故意这样做,以确保您构建的C扩展模块的构建方式与所使用的Python解释器的构建方式相同。 Extensions built this way are upwards compatible: they will work on 10.6 as well. 以这种方式构建的扩展是向上兼容的:它们也将在10.6上运行。 If you absolutely want to use 10.6 ABI features, you should use a Python that was built using the 10.6 SDK, for instance, from a recent python.org 64-bit installer or from MacPorts or Homebrew. 如果您绝对要使用10.6 ABI功能,则应使用通过10.6 SDK构建的Python,例如,它是从最新的python.org 64位安装程序,MacPorts或Homebrew中构建的。

I completely disagree with @Ned Deily 我完全不同意@Ned Deily

The poster obviously uses Enthought Python Distribution (EPD), and installing the whole new Python would require an installation of the whole new infrastracture. 张贴者显然使用了Enthought Python发行版(EPD),并且要安装整个新Python,就需要安装整个新基础设施。 I have the same situation. 我有同样的情况。 On MacBook with Mac Os X 10.6 the project (MeshPy) builds correctly, but on the Imac with Mac Os X 10.7 it does not (no 10.5 SDK is provided, and with this SDK EPD was built). 在装有Mac Os X 10.6的MacBook上,项目(MeshPy)可以正确构建,但是在装有Mac Os X 10.7的Imac上,则不能正确构建(未提供10.5 SDK,并且已构建了此SDK EPD)。 You can try to install this old SDK, however, a much simpler hack (hopefully it works) is to make a symlink: 您可以尝试安装此旧的SDK,但是,进行符号链接的方法要简单得多(希望它能起作用):

    sudo ln -sf MacOSX10.6.sdk MacOSX10.5.sdk

It worked for me. 它为我工作。

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

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