在Mac上找不到"openssl/aes.h"文件

11

我在尝试安装我找到的一个 Python 实现的代理重加密方案 这里 时遇到了问题。

运行命令 $ sudo python setup.py install 时,我得到了以下错误:

fatal error: 'openssl/aes.h' file not found

类似于这样的问题有一些(这个 或者 这个 (不适用于 Mac)),但是那里的任何答案都没有解决我的问题。

我尝试过以下方法(均来自我找到的答案):

  1. 运行命令 env LDFLAGS="-L$(brew --prefix openssl)/lib" CFLAGS="-I$(brew --prefix openssl)/include" pip install cryptography 并再次尝试;
  2. 安装 OpenSSL: brew install openssl 并再次尝试;
  3. 重新安装 Python: brew reinstall python 并再次尝试。

第一种方法返回:

Requirement already satisfied: cryptography in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Requirement already satisfied: six>=1.4.1 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from cryptography)
Requirement already satisfied: setuptools>=11.3 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from cryptography)
Requirement already satisfied: cffi>=1.4.1 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from cryptography)
Requirement already satisfied: pyasn1>=0.1.8 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from cryptography)
Requirement already satisfied: enum34 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from cryptography)
Requirement already satisfied: ipaddress in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from cryptography)
Requirement already satisfied: idna>=2.0 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from cryptography)
Requirement already satisfied: pycparser in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from cffi>=1.4.1->cryptography)

我正在使用OSX 10.12.6操作系统。

有什么想法吗?


1
sudo 命令会删除大部分常规用户的环境变量。例如 env LDFLAGS=... 这样的选项会消失,除非你使用 -e-E 等选项(如果我没记错的话)。请在非特权账户下构建项目,并使用 root 用户进行安装。 - jww
3个回答

24

首先检查由$(brew --prefix openssl)/include指出的路径是否存在。

如果上述步骤没有问题,你可以尝试

$ cd /usr/local/include
$ ln -s ../opt/openssl/include/openssl .

请看:Nginx无法找到OpenSSL开发头文件


当我安装gRPC for PHP时,遇到了“致命错误:未找到'openssl/rsa.h'文件”时,以下方法对我有效。 - Aswin Kumar

2

按照Vyper lang文档建议指定的环境变量,解决了我的问题:

For MacOS users:

Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries. This means that you will need to export some OpenSSL settings yourself, before you can install Vyper.

Use the following commands:

export CFLAGS="-I$(brew --prefix openssl)/include"
export LDFLAGS="-L$(brew --prefix openssl)/lib"

0
面对这个问题,升级至2.9.2,之前使用的版本是cryptography==1.0.1。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接