在Mac OS X上使用pip安装pycrypto时出现Broken Pipe错误

29 投票
2 回答
9684 浏览
提问于 2025-04-16 17:19

我正在尝试通过pip在OS X上安装pycrypto(版本2.3)。但是,当编译器试图编译MD2.c时,我遇到了一个“Broken pipe”的错误。在使用easy_install时,我也遇到了非常类似的错误。

这是我遇到的错误信息:

bash-3.2$ 
bash-3.2$ sudo pip install pycrypto
Password:
Downloading/unpacking pycrypto
  Running setup.py egg_info for package pycrypto
Installing collected packages: pycrypto
  Running setup.py install for pycrypto
    warning: GMP library not found; Not building Crypto.PublicKey._fastmath.
    building 'Crypto.Hash.MD2' extension
    gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -fwrapv -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch ppc -arch x86_64 -pipe -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c src/MD2.c -o build/temp.macosx-10.6-universal-2.6/src/MD2.o
    /usr/libexec/gcc/powerpc-apple-darwin10/4.2.1/as: assembler (/usr/bin/../libexec/gcc/darwin/ppc/as or /usr/bin/../local/libexec/gcc/darwin/ppc/as) for architecture ppc not installed
    Installed assemblers are:
    /usr/bin/../libexec/gcc/darwin/x86_64/as for architecture x86_64
    /usr/bin/../libexec/gcc/darwin/i386/as for architecture i386
    src/MD2.c:134: fatal error: error writing to -: Broken pipe
    compilation terminated.
    lipo: can't open input file: /var/tmp//cc47qHNI.out (No such file or directory)
    error: command 'gcc-4.2' failed with exit status 1
    Complete output from command /usr/bin/python -c "import setuptools;__file__='/Users/damusin/tmp/pycrypto/pycrypto-2.3/build/pycrypto/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-W6xQ61-record/install-record.txt:
    running install

running build

running build_py

running build_ext

warning: GMP library not found; Not building Crypto.PublicKey._fastmath.

building 'Crypto.Hash.MD2' extension

gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -fwrapv -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch ppc -arch x86_64 -pipe -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c src/MD2.c -o build/temp.macosx-10.6-universal-2.6/src/MD2.o

/usr/libexec/gcc/powerpc-apple-darwin10/4.2.1/as: assembler (/usr/bin/../libexec/gcc/darwin/ppc/as or /usr/bin/../local/libexec/gcc/darwin/ppc/as) for architecture ppc not installed

Installed assemblers are:

/usr/bin/../libexec/gcc/darwin/x86_64/as for architecture x86_64

/usr/bin/../libexec/gcc/darwin/i386/as for architecture i386

src/MD2.c:134: fatal error: error writing to -: Broken pipe

compilation terminated.

lipo: can't open input file: /var/tmp//cc47qHNI.out (No such file or directory)

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

----------------------------------------
Command /usr/bin/python -c "import setuptools;__file__='/Users/damusin/tmp/pycrypto/pycrypto-2.3/build/pycrypto/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-W6xQ61-record/install-record.txt failed with error code 1
Storing complete log in /Users/admin/.pip/pip.log
bash-3.2$ 
bash-3.2$ 

我尝试使用mac ports来安装这个包,命令是“sudo port install py26-crypto”,看起来安装得很顺利,但在运行“fab”(Fabric)命令时,它告诉我pycrypto包缺失。

我还尝试了YH Wong在这里推荐的“ARCHFLAGS”命令,但没有成功:https://superuser.com/questions/259278/python-2-6-1-pycrypto-2-3-pypi-package-broken-pipe-during-build

我使用的是Mac OS X 10.6.7,Python版本是2.6.6,并且已经安装了XCode。

2 个回答

2

Xcode 5.1

ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip2.7 install pycrypto
65

如果你安装了Xcode 4,可以在使用 pipeasy_install 之前先设置一下 ARCHFLAGS

sudo bash
export ARCHFLAGS='-arch i386 -arch x86_64'
pip ...

问题在于,Xcode 4 不再支持 -arch ppc 这个选项,而在 Mac OS X 10.6 上的系统自带 Python 2.6 需要用到这三种架构来构建通用的 C 扩展模块。如果你在使用 sudo 命令之前设置了这个环境变量,它可能不会被传递到 sudo 的环境中。

撰写回答