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

发布于 2024-12-02 10:21:59 字数 1721 浏览 0 评论 0原文

我在 Mac OS X 版本 10.6 上使用 Python。我最近安装了最新的 Mac OS X 开发工具 SDK,其中包含 GCC。我拥有的 SDK 是:

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

每当我使用需要编译的“setup.py install”安装 python 包时,我希望将 Mac OS X 10.6 与 Python/distutils 一起使用。

我注意到 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

我该如何纠正这个问题?我希望它改用 10.6 SDK。

现在,当我在需要 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

它在其路径中调用 10.5 SDK。

我使用 Python 的 Enthought Python Distribution 安装,以防产生影响。

非常感谢。

I use Python on Mac OS X version 10.6. I recently installed the newest Mac OS X developer tools SDK, which has GCC in it. The SDKs I have are:

$ 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.

I notice that Python passes the -isysroot flags and paths to Mac OS X 10.5 (not 10.6), i.e.:

$ 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.

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:

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.

I use the Enthought Python Distribution installation of Python in case that makes a difference.

Thanks very much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半边脸i 2024-12-09 10:22:00

这是一项功能,不应让您担心。 Distutils 故意这样做是为了确保您构建的 C 扩展模块的构建方式与正在使用的 Python 解释器的构建方式相同。以这种方式构建的扩展是向上兼容的:它们也可以在 10.6 上运行。如果您绝对想使用 10.6 ABI 功能,则应该使用使用 10.6 SDK 构建的 Python,例如,来自最新的 python.org 64 位安装程序或来自 MacPorts 或 Homebrew。

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. Extensions built this way are upwards compatible: they will work on 10.6 as well. 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.

别再吹冷风 2024-12-09 10:22:00

我完全不同意@Ned Deily

海报显然使用了 Enthought Python Distribution (EPD),安装全新的 Python 需要安装全新的基础设施。
我也有同样的情况。在配备 Mac Os X 10.6 的 MacBook 上,项目 (MeshPy) 可以正确构建,但在配备 Mac Os X 10.7 的 Imac 上却无法正确构建(未提供 10.5 SDK,并且使用此 SDK 构建了 EPD)。您可以尝试安装这个旧的 SDK,但是,一个更简单的技巧(希望它有效)是创建一个符号链接:

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

它对我有用。

I completely disagree with @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.
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). You can try to install this old SDK, however, a much simpler hack (hopefully it works) is to make a symlink:

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

It worked for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文