【问题标题】:"error: command 'x86_64-linux-gnu-gcc' failed with exit status 1" in virtualenv“错误:命令'x86_64-linux-gnu-gcc'失败,退出状态为1”在virtualenv中
【发布时间】:2015-01-23 16:01:06
【问题描述】:

环境: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 添加到Python 的virtualenv 版本吗?

【问题讨论】:

  • 这应该移到 ServerFault 吗?

标签: python-2.7 pip virtualenv linux-mint


【解决方案1】:

我在 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 是一个孤立的环境。对此的任何澄清表示赞赏。

【讨论】:

  • 这也适用于 Ubuntu 14.10!非常感谢@user1063287,你拯救了我的一天! :)
  • 很高兴听到@DhruvSingh
  • 来自文档:“virtualenv 是一个创建隔离 Python 环境的工具。”它们的意思是独立于 Python 包 的。来自外部系统的 C 库、头文件、构建工具等都是可见的,甚至是您的 Python 二进制文件。它不是虚拟机或单独的 Python 二进制安装。
  • 对于“枕头”,您还需要sudo apt-get install build-essential libjpeg-dev libzlib-dev
【解决方案2】:

这可能是 pip 中的问题。要解决,请尝试:

sudo apt-get remove python-pip

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

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

sudo python get-pip.py

【讨论】:

    【解决方案3】:

    为我工作:
    只需先安装 python2.7-dev
    sudo apt-get install python2.7-dev

    【讨论】:

    • 也为我工作!太有帮助了xD
    【解决方案4】:

    对我来说,lxml 的安装在编译时失败了。我按照 lxml 的安装说明减少了编译器优化:

    sudo CFLAGS="-O0"  pip install lxml
    

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

    【讨论】:

      【解决方案5】:

      大多数时候这些都是依赖问题。

      按照 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 &lt;openssl/aes.h&gt;

      编译器清楚地表明它需要这个文件 - 但它不在文件系统中。

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

      1. 找出您的发行版需要哪个软件包: 例如对于 Ubuntu,您可以转到 The Ubuntu Package Search Site 并输入您要查找的丢失文件。在这种情况下,“aes.h
      2. 使用您的发行版包管理工具安装所需的包: 例如对于 Ubuntu:

        aptitude install libssl-dev

      3. 在你的 virtualenv 中使用 pip 重试:

        pip install requests[security]

      【讨论】:

      • 是的! install libssl-dev 解决了我在尝试安装 bpython 一个全新的 Ubuntu 14.04 机器时遇到的问题。谢谢一百万!
      • 在我的情况下,缺少的库是 libffi-dev
      【解决方案6】:

      cffi 库需要libffi-dev

      sudo apt-get install libffi libffi-dev
      

      【讨论】:

        【解决方案7】:

        最简单的方法是:

        sudo apt-get build-dep python-imaging
        

        然后

        pip install pillow
        

        【讨论】:

          【解决方案8】:

          这对我有用,12.04,python2.7.6 for package lxml

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

          【讨论】:

          • 我认为您的意思是 sudo apt-get install 而不是 pip?
          【解决方案9】:

          在 Ubuntu 16.04.1 中,这对我有用:

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

          【讨论】:

            猜你喜欢
            • 2016-01-08
            • 2017-05-20
            • 2016-04-18
            • 1970-01-01
            • 2016-08-27
            • 1970-01-01
            • 1970-01-01
            • 2022-12-03
            • 2016-05-05
            相关资源
            最近更新 更多