环境: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
:
Installing lxml in virtualenv via pip install error: command 'x86_64-linux-gnu-gcc' failed
Pillow installation error: command 'gcc' failed with exit status 1
fatal error: Python.h: No such file or directory
我对此建议感到困惑,因为我的理解是使用类似的东西:
sudo apt-get install python2.7-dev
会将它添加到Python的main * system *实例中,而不是virtualenv
中的那个。 (见 - https://unix.stackexchange.com/a/56392/92486)
我可以只将python2.7-dev
添加到virtualenv
版本的Python中吗?
答案 0 :(得分:20)
大多数情况下,这些都是依赖性问题。
在gcc编译器的堆栈跟踪之后,可以看到丢失的文件。有时安装Python开发包是不够的。
例如:
我试着在我的virtualenv foo 中做pip install requests[security]
。这是pip-installer给我的结果。
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>
编译器非常清楚它要求这个文件 - 但它不在文件系统中。
知道这一点,唯一要做的就是:安装所需的库!
使用您的发行包管理工具安装所需的包: 例如对于Ubuntu:
aptitude install libssl-dev
在你的virtualenv中重试pip:
pip install requests[security]
答案 1 :(得分:16)
我通过Linux Mint 17中的Synaptic Package Manager安装了python2.7-dev
。
然后我可以在virtualenv
中完成以下内容:
pip install pillow
pip install pycrypto
然后我通过Synaptic安装了libxml2-dev
和libxslt1-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 :(得分:5)
为我工作:
首先安装python2.7-dev
sudo apt-get install python2.7-dev
答案 3 :(得分:2)
在Ubuntu 16.04.1中,这对我有用:
sudo apt-get install libxml2-dev libxslt1-dev python-dev
答案 4 :(得分:1)
对我来说,lxml的安装在编译时失败了。我按照安装lxml的说明进行操作,并减少了编译器优化:
sudo CFLAGS="-O0" pip install lxml
执行此操作后,lxml的编译成功。
答案 5 :(得分:0)
这可能是一个问题。要解决,请尝试:
sudo apt-get remove python-pip
要安装pip,请安全下载get-pip.py。
https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
答案 6 :(得分:0)
cffi
库需要libffi-dev
:
sudo apt-get install libffi libffi-dev
答案 7 :(得分:0)
最简单的方法是:
sudo apt-get build-dep python-imaging
然后
pip install pillow
答案 8 :(得分:0)
这适用于我,12.04,python2.7.6包 lxml
sudo pip install libxml2 libxml2-dev libxslt1-dev
sudo pip install lxml