致命错误:升级到python 3.2并从virtualenv安装某些模块后找不到'string.h'文件

时间:2012-11-27 16:20:45

标签: python pip pycrypto python-3.2

我在Mac OSX 10.8(Mountain Lion)上,刚安装了Python 3.2.3。

使用该版本的python从虚拟环境安装pycrypto时:

$ virtualenv --no-site-packages -p /usr/local/bin/python3.2-32 venv
$ source venv/bin/activate
$ pip install pycrypto

我收到错误:

gcc-4.2 not found, using clang instead

building 'Crypto.Hash._MD2' extension

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

Compiling with an SDK that doesn't seem to exist: /Developer/SDKs/MacOSX10.6.sdk

Please check your Xcode installation

clang -fno-strict-aliasing -fno-common -dynamic -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/Library/Frameworks/Python.framework/Versions/3.2/include/python3.2m -c src/MD2.c -o build/temp.macosx-10.6-intel-3.2/src/MD2.o

src/MD2.c:30:10: fatal error: 'string.h' file not found

#include <string.h>

         ^

1 error generated.

error: command 'clang' failed with exit status 1

尝试安装加密时会发生类似的事情。

As of version 2.4, Pycrypto says it supports python 3.

我在xcode开发者文件夹中添加了一个符号链接:

$ sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer /Developer

但该文件夹中存在的所有内容都是MacOSX10.7.sdk MacOSX10.8.sdk(不是上面需要的MacOSX10.6.sdk)。

我在系统中遗漏了什么?如何告诉它使用其他SDK?

1 个答案:

答案 0 :(得分:4)

通过执行以下操作来实现它:

与上面的评论一样,确保安装了命令行工具,这也安装了系统标题:

  

启动Xcode,打开Xcode - &gt;首选项...并转到“下载”标签。在“组件”下,确保已安装命令行工具;这也将在系统文件夹中安装系统头文件。

按照this answer中的说明,创建指向开发者文件夹的符号链接:

sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer /Developer

但是,仍然会出现错误消息:

Compiling with an SDK that doesn't seem to exist: /Developer/SDKs/MacOSX10.6.sdk

这与issue that Python 3.2 assumes you are using Mac OSX 10.6

有关

我修复了这个问题,这是通过伪装OSX 10.6环境创建一个从它到OSX 10.8环境的符号链接:

sudo ln -s /Developer/SDKs/MacOSX10.8.sdk MacOSX10.6.sdk

包已成功安装。