在虚拟环境中出现“error: command 'x86_64-linux-gnu-gcc' failed with exit status 1”的错误。

26

环境:Linux Mint 17 Cinnamon。

显示以下错误:

error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

当在 virtualenv 中尝试以下操作时:

pip install lxml
pip install pillow
pip install pycrypto
pip install pymongo (fails but still shows in pip freeze)

这里有几个解决方案建议安装python2.7-dev

安装Pillow出错:Setup script exited with error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

在virtualenv中通过pip安装lxml时,出现错误:command 'x86_64-linux-gnu-gcc' failed

Pillow安装出错:command 'gcc' failed with exit status 1

fatal error: Python.h: No such file or directory

然而,我对这个建议感到困惑,因为据我所知,使用类似以下的东西:

sudo apt-get install python2.7-dev

将此添加到Python的主*系统实例*中,而不是 virtualenv 中的实例。 (请参见- https://unix.stackexchange.com/a/56392/92486

我能否仅将 python2.7-dev 添加到Python的 virtualenv 版本中?


这个应该移动到ServerFault吗? - Marcos Pérez Gude
9个回答

20

大多数情况下这些问题都是依赖项问题。

按照gcc编译器的堆栈跟踪,可以看到缺少的文件。有时安装Python开发包并不足够。

例如:我尝试在虚拟环境foo中执行pip install requests[security]。这是pip安装程序给我的结果。

Failed building wheel for cryptography
Running setup.py bdist_wheel for cffi
Stored in directory: /root/.cache/pip/wheels/99/e7/9a/68b1c8ca6f6f92b5feebd4d9434f50712b84f6a66d1285ea21
Successfully built cffi
Failed to build cryptography
Installing collected packages: cffi, cryptography, pyOpenSSL, ndg-httpsclient, requests
Running setup.py install for cryptography
Complete output from command /opt/foo/django-cms-virtualenv/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-eZaLAG/cryptography/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-BwgYTp-record/install-record.txt --single-version-externally-managed --compile --install-headers /opt/foo/django-cms-virtualenv/include/site/python2.7/cryptography:
running install
running build
running build_py
running egg_info
writing requirements to src/cryptography.egg-info/requires.txt
writing src/cryptography.egg-info/PKG-INFO
writing top-level names to src/cryptography.egg-info/top_level.txt
writing dependency_links to src/cryptography.egg-info/dependency_links.txt
writing entry points to src/cryptography.egg-info/entry_points.txt
warning: manifest_maker: standard file '-c' not found

reading manifest file 'src/cryptography.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
no previously-included directories found matching 'docs/_build'
warning: no previously-included files matching '*' found under directory 'vectors'
writing manifest file 'src/cryptography.egg-info/SOURCES.txt'
running build_ext
building '_Cryptography_cffi_a269d620xd5c405b7' extension
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/cryptography/hazmat/bindings/__pycache__/_Cryptography_cffi_a269d620xd5c405b7.c -o build/temp.linux-x86_64-2.7/src/cryptography/hazmat/bindings/__pycache__/_Cryptography_cffi_a269d620xd5c405b7.o
src/cryptography/hazmat/bindings/__pycache__/_Cryptography_cffi_a269d620xd5c405b7.c:217:25: fatal error: openssl/aes.h: Datei oder Verzeichnis nicht gefunden
 #include <openssl/aes.h>
                         ^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

重要的部分是:#include <openssl/aes.h>

编译器很清楚地表示它需要这个文件,但在文件系统中找不到它。

知道了这一点,唯一剩下要做的就是:安装所需的库!

  1. 找出您的发行版所需的软件包: 例如,对于Ubuntu,您可以访问Ubuntu软件包搜索站点并输入您要查找的缺失文件。 在本例中为“aes.h
  2. 使用您的发行版软件包管理工具安装所需的软件包: 例如,对于Ubuntu:

    aptitude install libssl-dev

  3. 在您的虚拟环境中使用pip重试:

    pip install requests[security]


2
您IP地址为143.198.54.68,由于运营成本限制,当前对于免费用户的使用频率限制为每个IP每72小时10次对话,如需解除限制,请点击左下角设置图标按钮(手机用户先点击左上角菜单按钮)。 - kramer65
1
在我的情况下,缺少的库是 libffi-dev - onurmatik

17
我在Linux Mint 17中通过Synaptic软件包管理器安装了python2.7-dev。 然后我可以在virtualenv中完成以下操作:
pip install pillow
pip install pycrypto

然后我通过Synaptic安装了libxml2-devlibxslt1-dev,并成功完成了以下操作:

pip install lxml

我这样做是为了确保pymongo安装过程中不会出现任何错误:

pip uninstall pymongo
pip install pymongo  # i defined the version i needed ie pip install pymongo==2.6.2

我仍然不明白这怎么能解决问题,因为我认为virtualenv是一个独立的环境。如有任何澄清,请告知。

2
这对于Ubuntu 14.10同样适用!非常感谢@user1063287,你救了我的一天! :) - Dhruv
很高兴听到@DhruvSingh。 - user1063287
从文档中可以看到:"virtualenv是一个创建独立Python环境的工具。" 它所说的独立是指在Python包方面的隔离。外部系统的C库、头文件、构建工具等是可见的,甚至你的Python二进制文件也是如此。它不是一个虚拟机或单独的Python二进制安装。 - Dan Getz
2
对于“pillow”,您还需要sudo apt-get install build-essential libjpeg-dev libzlib-dev - hobs

5

我的要求是:
安装python2.7-dev
sudo apt-get install python2.7-dev


1
对我也起作用了!太有帮助了 xD - hsiaomichiu

2

In Ubuntu 16.04.1 this worked for me:

sudo apt-get install libxml2-dev libxslt1-dev python-dev

1

对我来说,lxml的安装在编译时失败了。我按照安装lxml的说明进行了操作,并降低了编译器的优化:

sudo CFLAGS="-O0"  pip install lxml

做完这个之后,lxml 的编译成功了。

0

最简单的方法是:

sudo apt-get build-dep python-imaging

然后

pip install pillow

0

这可能是pip中的一个问题。为了解决它,请尝试:

sudo apt-get remove python-pip

要安装pip,请安全地下载get-pip.py。

https://bootstrap.pypa.io/get-pip.py

sudo python get-pip.py


0

cffi 库需要安装 libffi-dev

sudo apt-get install libffi libffi-dev

0

这对我来说可行,12.04,python2.7.6适用于lxml

sudo pip install libxml2 libxml2-dev libxslt1-dev
sudo pip install lxml

我认为你想说的是sudo apt-get install而不是pip? - Vinay

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