pip在virtualenv中安装lxml失败

pip在virtualenv中安装lxml失败

本文介绍了Cygwin上的Python 2.7 pip在virtualenv中安装lxml失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读了所有可以找到的内容并尝试了许多事情之后,我无法确定原因/解决方案...

After reading everything I can find, and attempting many things, I can't identify the cause/solution for this...

$ pip install lxml --no-compile --only-binary=:all | grep -v 'copying\|creating'
Collecting lxml
  Using cached lxml-3.7.2.tar.gz
Building wheels for collected packages: lxml
  Running setup.py bdist_wheel for lxml: started
  Running setup.py bdist_wheel for lxml: finished with status 'error'
  Complete output from command /cygdrive/c/Programs/Python27.v_env.Scrapy/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-ADWe5d/lxml/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmphkkbinpip-wheel- --python-tag cp27:
  Building lxml version 3.7.2.
  Building without Cython.
  Using build configuration of libxslt 1.1.29
  Building against libxml2/libxslt in the following directory: /usr/lib
  running bdist_wheel
  running build
  running build_py
  Failed building wheel for lxml
  running build_ext
  building 'lxml.etree' extension
  gcc -fno-strict-aliasing -ggdb -O2 -pipe -Wimplicit-function-declaration -fdebug-prefix-map=/usr/src/ports/python/python-2.7.12-1.x86_64/build=/usr/src/debug/python-2.7.12-1 -fdebug-prefix-map=/usr/src/ports/python/python-2.7.12-1.x86_64/src/Python-2.7.12=/usr/src/debug/python-2.7.12-1 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/include/libxml2 -Isrc/lxml/includes -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.cygwin-2.6.1-x86_64-2.7/src/lxml/lxml.etree.o -w
  src/lxml/lxml.etree.c:84:20: error: Python.h: No such file or directory
  src/lxml/lxml.etree.c:86:6: error: #error Python headers needed to compile C extensions, please install development version of Python.
  Compile failed: command 'gcc' failed with exit status 1
  cc -I/usr/include/libxml2 -I/usr/include/libxml2 -c /tmp/xmlXPathInittcKSfa.c -o tmp/xmlXPathInittcKSfa.o
  unable to execute 'cc': No such file or directory
  *********************************************************************************
  Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
  *********************************************************************************
  error: command 'gcc' failed with exit status 1

  ----------------------------------------
  Running setup.py clean for lxml
Failed to build lxml
Installing collected packages: lxml
  Running setup.py install for lxml: started
    Running setup.py install for lxml: finished with status 'error'
    Complete output from command /cygdrive/c/Programs/Python27.v_env.Scrapy/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-ADWe5d/lxml/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-Hu4l_V-record/install-record.txt --single-version-externally-managed --no-compile --install-headers /cygdrive/c/Programs/Python27.v_env.Scrapy/include/site/python2.7/lxml:
    Building lxml version 3.7.2.
    Building without Cython.
    Using build configuration of libxslt 1.1.29
    Building against libxml2/libxslt in the following directory: /usr/lib
    running install
    running build
    running build_py
    running build_ext
    building 'lxml.etree' extension
    gcc -fno-strict-aliasing -ggdb -O2 -pipe -Wimplicit-function-declaration -fdebug-prefix-map=/usr/src/ports/python/python-2.7.12-1.x86_64/build=/usr/src/debug/python-2.7.12-1 -fdebug-prefix-map=/usr/src/ports/python/python-2.7.12-1.x86_64/src/Python-2.7.12=/usr/src/debug/python-2.7.12-1 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/include/libxml2 -Isrc/lxml/includes -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.cygwin-2.6.1-x86_64-2.7/src/lxml/lxml.etree.o -w
    src/lxml/lxml.etree.c:84:20: error: Python.h: No such file or directory
    src/lxml/lxml.etree.c:86:6: error: #error Python headers needed to compile C extensions, please install development version of Python.
    Compile failed: command 'gcc' failed with exit status 1
    cc -I/usr/include/libxml2 -I/usr/include/libxml2 -c /tmp/xmlXPathInitSsqVxY.c -o tmp/xmlXPathInitSsqVxY.o
unable to execute 'cc': No such file or directory
  *********************************************************************************
  Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
  *********************************************************************************
  error: command 'gcc' failed with exit status 1

----------------------------------------
Command "/cygdrive/c/Programs/Python27.v_env.Scrapy/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-ADWe5d/lxml/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-Hu4l_V-record/install-record.txt --single-version-externally-managed --no-compile --install-headers /cygdrive/c/Programs/Python27.v_env.Scrapy/include/site/python2.7/lxml" failed with error code 1 in /tmp/pip-build-ADWe5d/lxml/

据我所知,据报失踪的物品确实存在...

The items reported as missing, exist, as far I can see...

$ find /usr/include -type f -name "Python.h"
/usr/include/python2.7/Python.h

$ apt-cyg show python-devel python-lxml libxml2-devel libxslt-devel | grep 'sdesc\|require\|version'
sdesc: "Python language interpreter"
requires: bash pkg-config python
version: 2.7.12-1
sdesc: "Python XML2/XSLT bindings"
requires: cygwin libxml2 libxslt python python-beautifulsoup
version: 3.4.4-1
sdesc: "GNOME XML library (development)"
requires: bash libxml2 pkg-config
version: 2.9.4-1
sdesc: "GNOME XSLT library (development)"
requires: bash cygwin-devel libgcrypt-devel libgpg-error-devel libiconv-devel liblzma-devel libxml2-devel libxslt pkg-config zlib-devel
version: 1.1.29-1

$ pip list | grep 'pip\|setup\|wheel'
pip (9.0.1)
setuptools (34.1.1)
wheel (0.29.0)

我试图避免使用在"pip install"中使用的选项进行编译,但无济于事.任何见解将不胜感激.谢谢.

I've tried to avoid the compile with options I used on 'pip install', to no avail. Any insights would be greatly appreciated. Thanks.

推荐答案

我遇到了类似的问题.我必须安装:

I had a similar problem. I had to install:

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

根据 http://lxml.de/installation.html

这篇关于Cygwin上的Python 2.7 pip在virtualenv中安装lxml失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 06:15