【问题标题】:Unable to Install with easy_install or pip on mac无法在 mac 上使用 easy_install 或 pip 安装
【发布时间】:2025-10-06 00:40:01
【问题描述】:

我正在尝试使用 easy_install(和 pip)安装 lxml 和 pycrypto 模块,但收到类似的错误消息

Running lxml-2.3.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-kGsWMh/lxml-2.3.4/egg-dist-tmp-Gjqy3f
Building lxml version 2.3.4.
Building without Cython.
Using build configuration of libxslt 1.1.24
In file included from /usr/include/limits.h:63,
                 from /Developer/usr/bin/../lib/gcc/powerpc-apple-darwin10/4.0.1/include/limits.h:10,
                 from /Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:19,
                 from src/lxml/lxml.etree.c:4:
/usr/include/sys/cdefs.h:540:4: error: #error Unknown architecture
In file included from /usr/include/limits.h:64,
                 from /Developer/usr/bin/../lib/gcc/powerpc-apple-darwin10/4.0.1/include/limits.h:10,
                 from /Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:19,
                 from src/lxml/lxml.etree.c:4:
/usr/include/machine/limits.h:10:2: error: #error architecture not supported
In file included from /usr/include/sys/_types.h:33,
                 from /usr/include/_types.h:27,
                 from /usr/include/stdio.h:67,
                 from /Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:33,
                 from src/lxml/lxml.etree.c:4:
/usr/include/machine/_types.h:36:2: error: #error architecture not supported
In file included from /usr/include/_types.h:27,
                 from /usr/include/stdio.h:67,
                 from /Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:33,
                 from src/lxml/lxml.etree.c:4:
/usr/include/sys/_types.h:94: error: syntax error before ‘__darwin_blkcnt_t’
    src/lxml/lxml.etree.c:165640: error: syntax error before ‘val’
    src/lxml/lxml.etree.c:165645: error: syntax error before ‘val’

bla bla 。 . .

src/lxml/lxml.etree.c:165645: error: syntax error before ‘val’

lipo: can't figure out the architecture type of: /var/folders/f3/2q2x2p015kzgd4nbrn_qwykh0000gn/T//cc1pnrww.out

error: command 'gcc-4.0' failed with exit status 1

我在尝试安装 pycrypto 时也遇到了类似的语法错误。我试过this answer,但没有成功。我尝试使用 setuptools-0.6c11-py2.6.egg 和 setuptools-0.6c11-py2.7.egg 设置 python 2.6 和 2.7 环境,但得到相同的输出。

我在网上搜索了很多,但找不到解决方案。

编辑:我在 macbook pro 2010 上使用 OSX 10.7,并安装了 XCode 4 和 3

在尝试上面链接中的命令时,我会将 args 替换为最新版本。

python setup.py build --static-deps --libxml2-version=2.7.8  --libxslt-version=1.1.26 
sudo python setup.py install

我在其他帖子上阅读并尝试过这个

STATIC_DEPS=true sudo easy_install --allow-hosts=lxml.de,*.python.org lxml

解决方案:

正如@jdi 建议的那样,我做了以下事情

$ brew install --use-llvm libxml2
$ brew install --use-llvm libxslt

link 安装 gcc,因为我仍然面临建议的选项 1 和 2 的问题

那么,要么这个

$ export ARCHFLAGS="-arch i386 -arch x86_64"
$ /usr/bin/python2.6 setup.py build
$ sudo /usr/bin/python2.6 setup.py install

或者这个,会起作用的

$ sudo env ARCHFLAGS="-arch i386 -arch x86_64" easy_install-2.6 lxml

同样适用于 pycrypto

【问题讨论】:

    标签: python lxml pip easy-install pycrypto


    【解决方案1】:

    这表明你没有正确地构建它:/Developer/usr/bin/../lib/gcc/powerpc-apple-darwin10,当然除非你是在一台旧的 powerpc 机器上。

    检查您正在运行的 OSX 版本,以及您用于构建 lxml 的命令。您可能需要在构建之前在 shell 中设置export ARCHFLAGS="-arch i386 -arch x86_64",以避免它与ppc 一起构建。不知道为什么你会得到一个旧拱门。

    另外,请确保您安装了最新的 Xcode。而且,如果您逐字逐句地跟踪您发布的链接,请确保您使用的是这些软件包的最新版本,而不是文字版本,因为该链接已有 3 年历史。

    如果一切都失败了,请安装 homebrew 并通过该软件包管理器进行安装。

    更新: XCode 4.2+ 更新后缺少 GCC 4.2 的选项

    选择一个

    1. 使用这个简单的指南安装 gcc 4.2:
      http://caiustheory.com/install-gcc-421-apple-build-56663-with-xcode-42

    2. 使用自制软件进行安装:

      brew tap homebrew/dupes
      brew install homebrew/dupes/apple-gcc42

    3. 完全忽略 gcc 并将 llvm 与 brew 一起使用

      brew install --use-llvm libxml2

    【讨论】:

    • 我已更新帖子以回答您的问题。我仍然不确定为什么 easy_install 不起作用,因为理想情况下,如果我正确使用了 easy_install,我不需要配置任何东西
    • @rajivvishwa:删除 xcode 3,并确保 xcode 4 更新到最新版本。如果它试图构建 ppc,你显然有一个架构问题。此外,请确保在最新的 xcode4 中进入首选项并让它安装命令行工具。我打赌你没有更新命令行工具,它仍在使用 xcode 3 工具构建。
    • 按照建议,我完全删除了 Xcode 3 并从苹果下载中安装了最新的命令行工具(Xcode 4 表示它已经安装)。但是现在有一个新问题,我没有 gcc-4.2 了 :( 所以这是我在做 easy_install 时看到的 unable to execute /usr/bin/gcc-4.2: No such file or directory error: command '/usr/bin/gcc-4.2' failed with exit status 1 我用谷歌搜索发现 Lion/XCode 4.2+ 不支持 gcc-4.2!现在怎么办?
    • @rajivvishwa:查看更新以了解如何处理。 3个选项。不过,您现在完全走在正确的道路上,因为它正在尝试使用正确的版本进行编译。
    • 我按照您的步骤进行操作,效果很好。我已经更新了帖子。谢谢!