Scrapy安装失败,错误提示“无法打开包含文件: 'openssl/aes.h'”

12 投票
4 回答
9822 浏览
提问于 2025-04-18 20:10

我正在尝试用 easy_install -U Scrapy 来安装 Scrapy,但出现了一个奇怪的错误:“无法打开包含文件”。有没有人知道这是怎么回事?以下是我完整的错误信息:

C:\Users\Mubashar Kamran>easy_install -U Scrapy
Searching for Scrapy
Reading https://pypi.python.org/simple/Scrapy/
Best match: scrapy 0.24.4
Processing scrapy-0.24.4-py2.7.egg
scrapy 0.24.4 is already the active version in easy-install.pth
Installing scrapy-script.py script to C:\Python27\Scripts
Installing scrapy.exe script to C:\Python27\Scripts
Installing scrapy.exe.manifest script to C:\Python27\Scripts

Using c:\python27\lib\site-packages\scrapy-0.24.4-py2.7.egg
Processing dependencies for Scrapy
Searching for cryptography>=0.2.1
Reading https://pypi.python.org/simple/cryptography/
Best match: cryptography 0.5.4
Downloading https://pypi.python.org/packages/source/c/cryptography/cryptography-
0.5.4.tar.gz#md5=4fd1f10e9f99009a44667fabe7980aec
Processing cryptography-0.5.4.tar.gz
Writing c:\users\mubash~1\appdata\local\temp\easy_install-jjms3i\cryptography-0.
5.4\setup.cfg
Running cryptography-0.5.4\setup.py -q bdist_egg --dist-dir c:\users\mubash~1\ap
pdata\local\temp\easy_install-jjms3i\cryptography-0.5.4\egg-dist-tmp-ry6bwd
C:\Python27\lib\distutils\dist.py:267: UserWarning: Unknown distribution option:
 'setup_requires'
  warnings.warn(msg)
_Cryptography_cffi_684bb40axf342507b.c
   Creating library c:\users\mubash~1\appdata\local\temp\easy_install-jjms3i\cry
ptography-0.5.4\cryptography\hazmat\primitives\__pycache__\Release\cryptography\
hazmat\primitives\__pycache__\_Cryptography_cffi_684bb40axf342507b.lib and objec
t c:\users\mubash~1\appdata\local\temp\easy_install-jjms3i\cryptography-0.5.4\cr
yptography\hazmat\primitives\__pycache__\Release\cryptography\hazmat\primitives\
__pycache__\_Cryptography_cffi_684bb40axf342507b.exp
_Cryptography_cffi_8f86901cxc1767c5a.c
   Creating library c:\users\mubash~1\appdata\local\temp\easy_install-jjms3i\cry
ptography-0.5.4\cryptography\hazmat\primitives\__pycache__\Release\cryptography\
hazmat\primitives\__pycache__\_Cryptography_cffi_8f86901cxc1767c5a.lib and objec
t c:\users\mubash~1\appdata\local\temp\easy_install-jjms3i\cryptography-0.5.4\cr
yptography\hazmat\primitives\__pycache__\Release\cryptography\hazmat\primitives\
__pycache__\_Cryptography_cffi_8f86901cxc1767c5a.exp
_Cryptography_cffi_4ed9e37dx4000d087.c
cryptography\hazmat\bindings\__pycache__\_Cryptography_cffi_4ed9e37dx4000d087.c(
194) : fatal error C1083: Cannot open include file: 'openssl/aes.h': No such fil
e or directory
error: c:\users\mubash~1\appdata\local\temp\easy_install-jjms3i\cryptography-0.5
.4\cryptography\hazmat\primitives\__pycache__\_Cryptography_cffi_684bb40axf34250
7b.pyd: Access is denied

4 个回答

2

只需要安装openssl就可以了。

brew install openssl

然后在你的~/.bash_profile文件中添加一些设置。

export LDFLAGS=-L/usr/local/opt/openssl/lib
export CPPFLAGS=-I/usr/local/opt/openssl/include

尽量不要使用--force这个参数来链接,因为这样可能会和系统的库发生冲突。

10

在OSX系统上

首先,你可以用命令 brew install openssl 来安装openssl。如果系统提示你链接没有创建,那么可以再执行 brew link openssl --force

接下来,用下面的命令来安装Scrapy:

env CRYPTOGRAPHY_OSX_NO_LINK_FLAGS=1 LDFLAGS="$(brew --prefix openssl)/lib/libssl.a $(brew --prefix openssl)/lib/libcrypto.a" CFLAGS="-I$(brew --prefix openssl)/include" pip install scrapy

如果你愿意的话,可以把 openssl 替换成 libressl

29

我在安装不同的Python应用时遇到了同样的错误。原来是我缺少了OpenSSL的开发包,后来通过以下方法解决了这个问题:

sudo apt-get install libssl-dev
1

如果你在安装scrapy的时候遇到错误,可以参考这个链接:http://community.spiceworks.com/how_to/38490-setting-up-scrapy-on-windows-7。这个链接详细介绍了在Windows 7和8上安装scrapy的最简单、最准确的方法,能帮助你避免出现错误。

撰写回答