Skip to main content
 首页 » 编程设计

python-2.7之"error: command ' x86_64-linux-gnu-gcc ' failed with exit status 1"在 virtualenv

2024年11月01日57artech

环境: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 Pillow error: Setup script exited with error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

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 的主要 *system* 实例,而不是 virtualenv 中的那个。 . (见 - https://unix.stackexchange.com/a/56392/92486)

我可以加 python2.7-dev刚到 virtualenv版本的Python?

请您参考如下方法:

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

按照 gcc 编译器的堆栈跟踪可以看到丢失的文件。有时安装 Python 开发包是不够的。

例如:
我试着做 pip install requests[security]在我的 virtualenv foo 中。这是 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 你可以去 The Ubuntu Package Search Site并输入您要查找的丢失文件。在这种情况下,“ aes.h
  • 使用您的发行版软件包管理工具安装所需的软件包:
    例如对于 Ubuntu:
    aptitude install libssl-dev
  • 在您的 virtualenv 中使用 pip 重试:
    pip install requests[security]