Python 尝试在OS X El Capitan上安装PyCrypto时出现致命错误
我正在尝试在OS X 10.11.3(El Capitan)上安装PyCrypto。我正在使用Python 3.5.1。我从下载了gzip文件并解压缩了它。然后,我按照说明运行了Python 尝试在OS X El Capitan上安装PyCrypto时出现致命错误,python,macos,python-3.x,osx-elcapitan,pycrypto,Python,Macos,Python 3.x,Osx Elcapitan,Pycrypto,我正在尝试在OS X 10.11.3(El Capitan)上安装PyCrypto。我正在使用Python 3.5.1。我从下载了gzip文件并解压缩了它。然后,我按照说明运行了python setup.py build,它似乎做了些什么,然后产生了以下输出: /usr/bin/clang -fno-strict-aliasing -fno-common -dynamic -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386 -arch x86_
python setup.py build
,它似乎做了些什么,然后产生了以下输出:
/usr/bin/clang -fno-strict-aliasing -fno-common -dynamic -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386 -arch x86_64 -fwrapv -Wall -Wstrict-prototypes -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/MD2.c -o build/temp.macosx-10.6-intel-2.7/src/MD2.o
src/MD2.c:30:10: fatal error: 'string.h' file not found
#include <string.h>
^
1 error generated.
error: command '/usr/bin/clang' failed with exit status 1
我试着用谷歌搜索,想知道该怎么做,但找不到任何有用的东西。如何安装PyCrypto
编辑:我还尝试了其他一些方法,如pip安装pycrypto
和sudo pip3安装pycrypto
,但都没有成功@l'l'l帮我做了一些奇怪的复杂的事情,这些事情我自己都不会做。答案如下。概述:
您正在尝试的手动构建看起来可能会失败,因为它引用了OSX10.6SDK,而您可能没有,并且在大多数情况下已经过时。此外,SDK现在的存储位置与10.6 SDK处于最佳状态时完全不同
新SDK位置:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
/Developer/SDKs/
/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/MD2.c -o build/temp.macosx-10.6-intel-2.7/src/MD2.o
src/MD2.c:30:10: fatal error: 'string.h' file not found
#include <string.h>
^
1 error generated.
error: command '/usr/bin/clang' failed with exit status 1
...
fatal error: 'string.h' file not found #include <string.h>
...
$ echo "#include <string.h>
#include <stdio.h>
int main() { printf(\"TEST\n\"); return 0; }" > t.c
$ clang t.c -o t
$ ./t
TEST
旧SDK位置:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
/Developer/SDKs/
/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/MD2.c -o build/temp.macosx-10.6-intel-2.7/src/MD2.o
src/MD2.c:30:10: fatal error: 'string.h' file not found
#include <string.h>
^
1 error generated.
error: command '/usr/bin/clang' failed with exit status 1
...
fatal error: 'string.h' file not found #include <string.h>
...
$ echo "#include <string.h>
#include <stdio.h>
int main() { printf(\"TEST\n\"); return 0; }" > t.c
$ clang t.c -o t
$ ./t
TEST
不存在/过时的SDK:
由于在尝试构建PyCrypto时,它似乎引用了MacOSX10.6.sdk
,因此需要考虑以下几点:
/usr/bin/clang -fno-strict-aliasing -fno-common -dynamic -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386 -arch x86_64 -fwrapv -Wall -Wstrict-prototypes -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/Library
从源代码构建:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
/Developer/SDKs/
/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/MD2.c -o build/temp.macosx-10.6-intel-2.7/src/MD2.o
src/MD2.c:30:10: fatal error: 'string.h' file not found
#include <string.h>
^
1 error generated.
error: command '/usr/bin/clang' failed with exit status 1
...
fatal error: 'string.h' file not found #include <string.h>
...
$ echo "#include <string.h>
#include <stdio.h>
int main() { printf(\"TEST\n\"); return 0; }" > t.c
$ clang t.c -o t
$ ./t
TEST
同样的错误;我们可能应该找出系统上是否存在
标题-让我们快速测试C
应用程序以找出:
测试C标头:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
/Developer/SDKs/
/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/MD2.c -o build/temp.macosx-10.6-intel-2.7/src/MD2.o
src/MD2.c:30:10: fatal error: 'string.h' file not found
#include <string.h>
^
1 error generated.
error: command '/usr/bin/clang' failed with exit status 1
...
fatal error: 'string.h' file not found #include <string.h>
...
$ echo "#include <string.h>
#include <stdio.h>
int main() { printf(\"TEST\n\"); return 0; }" > t.c
$ clang t.c -o t
$ ./t
TEST
我们可以通过发出以下命令来验证符号链接:
$ ls -lat
total 8
drwxr-xr-x 3 root wheel 102 Feb 21 15:54 .
lrwxr-xr-x 1 root wheel 99 Feb 21 15:54 MacOSX10.6.sdk -> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk
drwxr-xr-x 3 root wheel 102 Feb 21 15:52 ..
现在我们已经成功创建了符号链接,让我们再次尝试使用pip安装PyCrypto:
$ sudo pip install pycrypto
Collecting pycrypto
Downloading pycrypto-2.6.1.tar.gz (446kB)
100% |████████████████████████████████| 446kB 1.2GB/s
Installing collected packages: pycrypto
Running setup.py install for pycrypto ... done
Successfully installed pycrypto-2.6.1
没有错误!看来我们的问题解决了!嗯,几乎
我们仍然需要找出在构建期间设置错误(10.6)SDK的原因。让我们使用xcrun
工具查看默认设置:
$ xcrun --show-sdk-version
10.11
系统默认SDK设置为10.11,因此Python、PyCrypto或其他一些我们可能没有考虑到的异常情况必须将其错误地设置为10.6
更新:
在进行一些侦察之后,发现它似乎是用OSX10.6SDK构建的。此外,它还将SDK设置为10.6,并在整个Python\u框架的许多地方设置(过时的)路径。有这么多的参考文献,我不想把它们全部列出,尽管这里有一个例子:
Python_Framework Folder/Versions/3.5/lib/python3.5/config-3.5m/Makefile:79:CONFIGURE_CFLAGS= -arch i386 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk
我只能假设开发人员试图尽可能地向后兼容,然而,不幸的是,在这个过程中破坏了向前兼容
注意事项:
使用安装Python软件包可以在许多方面(软件包管理、更新、卸载等)使生活变得更加轻松。例如,安装PyCrypto只需发出以下命令:
$ sudo pip install pycrypto
如果有,您可以使用相应的版本号为该Python安装:
$ sudo pip3.5 install pycrypto
↳ 当我运行pip安装pycrypto
时,我在OSX El Capitan上遇到了一个可能相关的问题。我看到RuntimeError:autoconf error
。我所要做的就是运行sudoxcodebuild-license
并在查看许可协议后键入agree
。之后,我可以使用pip安装pycrypto。您是否安装了xcode或命令行工具?您需要这样才能使用标准库、llvm等。假设OSX10.11和Xcode 7.X也存在同样的问题,那么创建此符号链接是否可行?事实上,其他人似乎也有类似的问题,您是否检查了ls-al/usr/include
?如果这看起来不正确,可以尝试sudo ln-s/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/usr/include
?尝试取消设置动态库路径
?Argh。。。我考虑过使用pip。我没有这么做的唯一原因是我找到的文档没有提到它。无论如何,我尝试了pip安装pycrypto
,sudo-pip安装pycrypto
,以及sudo-pip3.5安装pycrypto
,每次我都遇到了同样的致命错误:'string.h'文件未找到
错误。再次尝试从Apple下载命令行工具,然后安装它们:。(您可能需要登录才能下载)。如果在此之后无法正常工作,则可能存在路径问题,需要解决。您也可以通过Xcode:@I'L'L安装,第一个链接告诉我“此页面已不存在,或者您登录的Apple ID没有查看此页面的权限。”。谢谢!!我必须先删除/重命名现有的MacOSX10.6.sdk
,然后它才能工作。验证与ls-lat
的链接对我来说是关键。谢谢你的指导!