简体   繁体   English

尝试在OS X El Capitan上安装PyCrypto时出现致命错误

[英]Fatal error when trying to install PyCrypto on OS X El Capitan

I am trying to install PyCrypto on OS X 10.11.3 (El Capitan). 我正在尝试在OS X 10.11.3(El Capitan)上安装PyCrypto。 I am using Python 3.5.1. 我使用的是Python 3.5.1。 I downloaded the gzip file from https://pypi.python.org/pypi/pycrypto and decompressed it. 我从https://pypi.python.org/pypi/pycrypto下载了gzip文件并对其进行了解压缩。 Then I ran python setup.py build like the instructions said and it appeared to do something, then it produced this output: 然后我按照说明运行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

I tried python3 setup.py build and got some very similar output: 我尝试了python3 setup.py build并获得了一些非常相似的输出:

/usr/bin/clang -fno-strict-aliasing -Wsign-compare -Wunreachable-code -fno-common -dynamic -fwrapv -Wall -Wstrict-prototypes -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.5/include/python3.5m -c src/MD2.c -o build/temp.macosx-10.6-intel-3.5/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

I tried Googling to figure out what to do, but I couldn't find anything useful. 我试着谷歌去弄清楚要做什么,但我找不到任何有用的东西。 How can I install PyCrypto? 我该如何安装PyCrypto?

EDIT: I also tried several other things like pip install pycrypto and sudo pip3 install pycrypto and they didn't work. 编辑:我还尝试了几个其他的东西,如pip install pycryptosudo pip3 install pycrypto ,他们没有工作。 @l'L'l helped me get it to work by doing several strange, complex things that I never would have though have myself. @ l'L'l帮助我通过做几件奇怪的,复杂的事情让我开始工作,这些东西虽然我自己也没有。 They are summarized in the answer below. 它们总结在下面的答案中。

Overview: 概述:

The manual build you're trying looks like it might be failing because it's referencing the OS X 10.6 SDK, which you likely don't have, and is outdated for the most part. 您正在尝试的手动构建看起来可能会失败,因为它引用了您可能没有的OS X 10.6 SDK,并且在很大程度上已经过时了。 Also, SDKs are now stored in a completely different location than when the 10.6 SDK was in it's prime. 此外,SDK现在存储在与10.6 SDK处于最佳状态时完全不同的位置。

New SDKs location: 新SDK位置:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/

Old SDKs location: 旧SDK位置:

/Developer/SDKs/

Non-existent / outdated SDK: 不存在/过时的SDK:

Since it appears that when trying to build PyCrypto it's referencing the MacOSX10.6.sdk there are several things to consider: 由于看起来在尝试构建PyCrypto时,它引用了MacOSX10.6.sdk因此需要考虑以下几点:

  1. Why does it reference an outdated SDK 为什么它引用了过时的SDK
  2. Where is the SDK it's referencing set 它引用的SDK在哪里设置
  3. What should be done to correct the issue 应该怎么做才能纠正这个问题

Unless we audit the source code carefully we might not know exactly where the incorrect flags are set, but we can do our best to work with the information we have. 除非我们仔细审核源代码,否则我们可能无法准确知道错误标志的设置位置,但我们可以尽力处理我们所拥有的信息。 From the error we can see that there are several instances where the 10.6 SDK's name pops up: 从错误中我们可以看到有几个实例会弹出10.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

Building from source: 从源头构建:

/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

Analyzing this we can see that the PyCrypto's MD2.c file is trying to be built using the flag -isysroot /Developer/SDKs/MacOSX10.6.sdk . 分析一下,我们可以看到PyCrypto的MD2.c文件试图使用标志-isysroot /Developer/SDKs/MacOSX10.6.sdk It might be worth trying pip instead: 可能值得尝试pip

Installing with pip: 用pip安装:

...
fatal error: 'string.h' file not found #include <string.h>
...

Same error; 同样的错误; we should probably find out if the <string.h> header even exists on the system — Let's make a quick test C application to find out: 我们应该知道系统上是否存在<string.h>标头 - 让我们快速测试C应用程序来找出:

Testing the C headers: 测试C头:

$ echo "#include <string.h>
#include <stdio.h>
int main() { printf(\"TEST\n\"); return 0; }" > t.c
$ clang t.c -o t
$ ./t
TEST

It's apparent the header does exist because the test worked fine. 很明显,标题确实存在,因为测试工作正常。 This tells us that the problem is more likely related directly to the 10.6 SDK (which doesn't seem to exist on the system). 这告诉我们问题更可能直接与10.6 SDK相关(系统上似乎不存在)。

Symlinking (non-existing) 10.6 SDK to 10.11 SDK: 符号化(不存在)10.6 SDK到10.11 SDK:

Since we haven't determined where the SDK is actually getting set we'll go ahead and try to create symlinks so that any reference of the old 10.6 SDK links to the latest SDK (10.11 at this time): 由于我们尚未确定SDK实际设置的位置,因此我们将继续尝试创建符号链接,以便旧的10.6 SDK的任何引用链接到最新的SDK(此时为10.11):

$ cd /Developer/SDKs
$ sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk MacOSX10.6.sdk

We can verify the symlink by issuing the following command: 我们可以通过发出以下命令来验证符号链接:

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

Now that we've successfully created the symlink let's try installing PyCrypto with pip once more: 现在我们已经成功创建了符号链接,让我们再次尝试使用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

No errors! 没错! It looks like our problem is solved! 看起来我们的问题已经解决了! Well, almost... 好吧,差不多......

We still need to figure out what is responsible for setting the wrong (10.6) SDK during builds. 我们仍然需要弄清楚在构建期间设置错误(10.6)SDK的原因。 Let's use the xcrun tool to see what the defaults are set at: 让我们使用xcrun工具查看默认设置:

$ xcrun --show-sdk-version
10.11

The system default SDK is set to 10.11, so it must be get set incorrectly to 10.6 by Python, PyCrypto, or some other anomaly we might not have considered. 系统默认SDK设置为10.11,因此必须通过Python,PyCrypto或我们可能未考虑的其他一些异常将其设置为10.6。

UPDATE: 更新:

After doing some recon it was discovered that Python 3 appears to be built with the OS X 10.6 SDK. 在进行一些重新调查之后,发现Python 3似乎是使用OS X 10.6 SDK构建的。 In addition it's also setting the SDK to 10.6 and setting the (outdated) path in numerous places throughout the Python_Framework . 此外,它还将SDK设置为10.6并在整个Python_Framework中的许多位置设置(过时的)路径。 There are so many references I won't bother listing them all, although here's an example: 有这么多的参考资料,我不打算将它们全部列出来,尽管这是一个例子:

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

I can only assume the developers were trying to be as backward compatible as possible, however, it's unfortunately breaking forward compatibility in the process. 我只能假设开发人员试图尽可能向后兼容,但不幸的是,它在这个过程中突破了兼容性。


Notes: 笔记:

Installing Python packages with pip can make life much easier in a lot of ways (package management, updating, uninstalling, etc.). 使用pip安装Python软件包可以通过很多方式(包管理,更新,卸载等)使生活变得更加轻松。 For example installing PyCrypto should just be a matter of issuing the command: 例如,安装PyCrypto只需要发出命令:

$ sudo pip install pycrypto

If you have multiple Python's you can use the version number to install for that Python accordingly: 如果您有多个Python ,则可以使用版本号为该Python安装:

$ sudo pip3.5 install pycrypto

https://pip.pypa.io/en/stable/installing/ ↳https //pip.pypa.io/en/stable/installing/

I had what might be a related issue on OSX El Capitan when I would run pip install pycrypto . 当我运行pip install pycrypto时,我在OSX El Capitan上遇到了可能相关的问题。 I was seeing RuntimeError: autoconf error . 我看到RuntimeError: autoconf error All I had to do was run sudo xcodebuild -license and type agree after reviewing the licence agreement. 我所要做的就是运行sudo xcodebuild -license并在审核许可协议后输入agree Afterward I was able to use pip to install pycrypto. 之后我能够使用pip来安装pycrypto。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM