使用PIP安装Libxml错误

这是我的错误:

(mysite)zjm1126@zjm1126-G41MT-S2:~/zjm_test/mysite$ pip install lxml
Downloading/unpacking lxml
Running setup.py egg_info for package lxml
Building lxml version 2.3.
Building without Cython.
ERROR: /bin/sh: xslt-config: not found


** make sure the development packages of libxml2 and libxslt are installed **


Using build configuration of libxslt
Installing collected packages: lxml
Running setup.py install for lxml
Building lxml version 2.3.
Building without Cython.
ERROR: /bin/sh: xslt-config: not found


** make sure the development packages of libxml2 and libxslt are installed **


Using build configuration of libxslt
building 'lxml.etree' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c src/lxml/lxml.etree.c -o build/temp.linux-i686-2.6/src/lxml/lxml.etree.o -w
src/lxml/lxml.etree.c:4: fatal error: Python.h: 没有那个文件或目录
compilation terminated.
error: command 'gcc' failed with exit status 1
Complete output from command /home/zjm1126/zjm_test/mysite/bin/python -c "import setuptools;__file__='/home/zjm1126/zjm_test/mysite/build/lxml/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-jOhgvD-record/install-record.txt --install-headers /home/zjm1126/zjm_test/mysite/include/site/python2.6:
Building lxml version 2.3.


Building without Cython.


ERROR: /bin/sh: xslt-config: not found






** make sure the development packages of libxml2 and libxslt are installed **






Using build configuration of libxslt


running install


running build


running build_py


running build_ext


building 'lxml.etree' extension


gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c src/lxml/lxml.etree.c -o build/temp.linux-i686-2.6/src/lxml/lxml.etree.o -w


src/lxml/lxml.etree.c:4: fatal error: Python.h: 没有那个文件或目录


compilation terminated.


error: command 'gcc' failed with exit status 1


----------------------------------------
Command /home/zjm1126/zjm_test/mysite/bin/python -c "import setuptools;__file__='/home/zjm1126/zjm_test/mysite/build/lxml/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-jOhgvD-record/install-record.txt --install-headers /home/zjm1126/zjm_test/mysite/include/site/python2.6 failed with error code 1
Storing complete log in /home/zjm1126/.pip/pip.log

我该怎么办?

更新:

(mysite)zjm1126@zjm1126-G41MT-S2:~/zjm_test/mysite$ pip install lxml
Downloading/unpacking lxml
Running setup.py egg_info for package lxml
Building lxml version 2.3.
Building without Cython.
Using build configuration of libxslt 1.1.26
Building against libxml2/libxslt in the following directory: /usr/lib
Installing collected packages: lxml
Running setup.py install for lxml
Building lxml version 2.3.
Building without Cython.
Using build configuration of libxslt 1.1.26
Building against libxml2/libxslt in the following directory: /usr/lib
building 'lxml.etree' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/libxml2 -I/usr/include/python2.6 -c src/lxml/lxml.etree.c -o build/temp.linux-i686-2.6/src/lxml/lxml.etree.o -w
src/lxml/lxml.etree.c:4: fatal error: Python.h: 没有那个文件或目录
compilation terminated.
error: command 'gcc' failed with exit status 1
Complete output from command /home/zjm1126/zjm_test/mysite/bin/python -c "import setuptools;__file__='/home/zjm1126/zjm_test/mysite/build/lxml/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-NJw2ws-record/install-record.txt --install-headers /home/zjm1126/zjm_test/mysite/include/site/python2.6:
Building lxml version 2.3.


Building without Cython.


Using build configuration of libxslt 1.1.26


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 -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/libxml2 -I/usr/include/python2.6 -c src/lxml/lxml.etree.c -o build/temp.linux-i686-2.6/src/lxml/lxml.etree.o -w


src/lxml/lxml.etree.c:4: fatal error: Python.h: 没有那个文件或目录


compilation terminated.


error: command 'gcc' failed with exit status 1


----------------------------------------
Command /home/zjm1126/zjm_test/mysite/bin/python -c "import setuptools;__file__='/home/zjm1126/zjm_test/mysite/build/lxml/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-NJw2ws-record/install-record.txt --install-headers /home/zjm1126/zjm_test/mysite/include/site/python2.6 failed with error code 1
Storing complete log in /home/zjm1126/.pip/pip.log

日志:

------------------------------------------------------------
/home/zjm1126/zjm_test/mysite/bin/pip run on Thu Mar  3 17:07:27 2011
Downloading/unpacking mysql-python
Running setup.py egg_info for package mysql-python
running egg_info
creating pip-egg-info/MySQL_python.egg-info
writing pip-egg-info/MySQL_python.egg-info/PKG-INFO
writing top-level names to pip-egg-info/MySQL_python.egg-info/top_level.txt
writing dependency_links to pip-egg-info/MySQL_python.egg-info/dependency_links.txt
writing pip-egg-info/MySQL_python.egg-info/PKG-INFO
writing top-level names to pip-egg-info/MySQL_python.egg-info/top_level.txt
writing dependency_links to pip-egg-info/MySQL_python.egg-info/dependency_links.txt
writing manifest file 'pip-egg-info/MySQL_python.egg-info/SOURCES.txt'
warning: manifest_maker: standard file '-c' not found
reading manifest file 'pip-egg-info/MySQL_python.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'MANIFEST'
warning: no files found matching 'ChangeLog'
warning: no files found matching 'GPL'
writing manifest file 'pip-egg-info/MySQL_python.egg-info/SOURCES.txt'
Installing collected packages: mysql-python
Running setup.py install for mysql-python
Running command /home/zjm1126/zjm_test/mysite/bin/python -c "import setuptools;__file__='/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-XuVIux-record/install-record.txt --install-headers /home/zjm1126/zjm_test/mysite/include/site/python2.6
running install
running build
running build_py
creating build
creating build/lib.linux-i686-2.6
copying _mysql_exceptions.py -> build/lib.linux-i686-2.6
creating build/lib.linux-i686-2.6/MySQLdb
copying MySQLdb/__init__.py -> build/lib.linux-i686-2.6/MySQLdb
copying MySQLdb/converters.py -> build/lib.linux-i686-2.6/MySQLdb
copying MySQLdb/connections.py -> build/lib.linux-i686-2.6/MySQLdb
copying MySQLdb/cursors.py -> build/lib.linux-i686-2.6/MySQLdb
copying MySQLdb/release.py -> build/lib.linux-i686-2.6/MySQLdb
copying MySQLdb/times.py -> build/lib.linux-i686-2.6/MySQLdb
creating build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/REFRESH.py -> build/lib.linux-i686-2.6/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.linux-i686-2.6/MySQLdb/constants
running build_ext
building '_mysql' extension
creating build/temp.linux-i686-2.6
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/include/mysql -I/usr/include/python2.6 -c _mysql.c -o build/temp.linux-i686-2.6/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -DUNIV_LINUX -DUNIV_LINUX
In file included from _mysql.c:29:
pymemcompat.h:10: fatal error: Python.h: 没有那个文件或目录
compilation terminated.
error: command 'gcc' failed with exit status 1
Complete output from command /home/zjm1126/zjm_test/mysite/bin/python -c "import setuptools;__file__='/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-XuVIux-record/install-record.txt --install-headers /home/zjm1126/zjm_test/mysite/include/site/python2.6:
running install


running build


running build_py


creating build


creating build/lib.linux-i686-2.6


copying _mysql_exceptions.py -> build/lib.linux-i686-2.6


creating build/lib.linux-i686-2.6/MySQLdb


copying MySQLdb/__init__.py -> build/lib.linux-i686-2.6/MySQLdb


copying MySQLdb/converters.py -> build/lib.linux-i686-2.6/MySQLdb


copying MySQLdb/connections.py -> build/lib.linux-i686-2.6/MySQLdb


copying MySQLdb/cursors.py -> build/lib.linux-i686-2.6/MySQLdb


copying MySQLdb/release.py -> build/lib.linux-i686-2.6/MySQLdb


copying MySQLdb/times.py -> build/lib.linux-i686-2.6/MySQLdb


creating build/lib.linux-i686-2.6/MySQLdb/constants


copying MySQLdb/constants/__init__.py -> build/lib.linux-i686-2.6/MySQLdb/constants


copying MySQLdb/constants/CR.py -> build/lib.linux-i686-2.6/MySQLdb/constants


copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-i686-2.6/MySQLdb/constants


copying MySQLdb/constants/ER.py -> build/lib.linux-i686-2.6/MySQLdb/constants


copying MySQLdb/constants/FLAG.py -> build/lib.linux-i686-2.6/MySQLdb/constants


copying MySQLdb/constants/REFRESH.py -> build/lib.linux-i686-2.6/MySQLdb/constants


copying MySQLdb/constants/CLIENT.py -> build/lib.linux-i686-2.6/MySQLdb/constants


running build_ext


building '_mysql' extension


creating build/temp.linux-i686-2.6


gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/include/mysql -I/usr/include/python2.6 -c _mysql.c -o build/temp.linux-i686-2.6/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -DUNIV_LINUX -DUNIV_LINUX


In file included from _mysql.c:29:


pymemcompat.h:10: fatal error: Python.h: 没有那个文件或目录


compilation terminated.


error: command 'gcc' failed with exit status 1


----------------------------------------
Command /home/zjm1126/zjm_test/mysite/bin/python -c "import setuptools;__file__='/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-XuVIux-record/install-record.txt --install-headers /home/zjm1126/zjm_test/mysite/include/site/python2.6 failed with error code 1
Exception information:
Traceback (most recent call last):
File "/home/zjm1126/zjm_test/mysite/lib/python2.6/site-packages/pip-0.8.1-py2.6.egg/pip/basecommand.py", line 130, in main
self.run(options, args)
File "/home/zjm1126/zjm_test/mysite/lib/python2.6/site-packages/pip-0.8.1-py2.6.egg/pip/commands/install.py", line 228, in run
requirement_set.install(install_options, global_options)
File "/home/zjm1126/zjm_test/mysite/lib/python2.6/site-packages/pip-0.8.1-py2.6.egg/pip/req.py", line 1043, in install
requirement.install(install_options, global_options)
File "/home/zjm1126/zjm_test/mysite/lib/python2.6/site-packages/pip-0.8.1-py2.6.egg/pip/req.py", line 559, in install
cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)
File "/home/zjm1126/zjm_test/mysite/lib/python2.6/site-packages/pip-0.8.1-py2.6.egg/pip/__init__.py", line 249, in call_subprocess
% (command_desc, proc.returncode))
InstallationError: Command /home/zjm1126/zjm_test/mysite/bin/python -c "import setuptools;__file__='/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-XuVIux-record/install-record.txt --install-headers /home/zjm1126/zjm_test/mysite/include/site/python2.6 failed with error code 1
360920 次浏览

**确保已安装libxml2和libxslt的开发包**

lxml文档中,假设你正在运行一个基于debian的发行版:

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

对于基于Debian的系统,安装python-lxmlpython3-lxml的已知构建依赖项就足够了。

sudo apt-get install build-dep python3-lxml

不,你错过了Python头文件。这主要发生在Linux上,当你使用系统Python时(有不这么做的理由,但这是另一个问题)。

你可能需要安装一些包,它可能被称为python-dev或python-devel。

 sudo yum install python-devel

 sudo aptitude install python-dev

或somesuch。

安装一个lxml二进制文件就可以了。检查这个

STATIC_DEPS=true easy_install lxml

这招对我很管用:

yum install libxslt-devel libxml2-devel

如果您使用的是Ubuntu/Lubuntu 13.04或Ubuntu 13.10,并且遇到“/usr/bin/ld: cannot find -lz”的问题,您可能还需要安装zlib1g-dev包:

sudo apt-get install -y zlib1g-dev

把它们放在一起:

sudo apt-get install -y libxml2-dev libxslt1-dev zlib1g-dev python3-pip
sudo pip3 install lxml

pymemcompat.h:10: fatal error: Python.h: 没有那个文件或目录

孩子,你应该用LANG=C发布你的错误日志,否则人们无法从你的日志中得到真正的原因。上面的日志显示:没有这样的文件或目录。

这意味着您应该安装Python的开发包。在Debian风格的发行版上通常是“python-dev”,在RHEL风格的发行版上通常是“python-devel”。

我通过增加服务器内存解决了这个问题。

我只运行了512mb,当我升级到1gb时就没有问题了。

在此之前,我还手动安装了每个包,试图解决这个问题,但我不确定这是否是必要的步骤。

error: command 'gcc' failed with exit status 1


yum remove audit
yum install gcc
yum install libxslt-devel libxml2-devel


cd lxml-x.x.x
python setup.py build
python setup.py install

以上所有答案都假设用户拥有特权/root帐户来安装所需的库。要在本地安装它,您需要执行以下步骤。只显示了概述,因为这些步骤可能会涉及到一些依赖项,这取决于您可能遗漏的依赖项

1.下载并编译libxml2-2.9.1 &libxsl -1.1.28(版本可能会更改)

2.使用Configure将libxml和libxslt的每个安装路径配置为某个本地目录。例./configure --prefix=/home_dir/dependencies/libxslt_path

3.运行make,然后运行make install

4.从源代码下载并编译lxml

安装要求:

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

现在,你可以用pip包管理工具安装它:

pip install lxml

对于python3用户:

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


pip3 install lxml

我使用的是Ubuntu 12,这对我来说是有效的:

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

在Windows 8上使用cygwin 64。

我有……

pip install LXML (…)< / p >

gcc -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -ggdb -O2 -pipe -Wimplicit-function-declaration -fdebug-prefix-map=/usr/src/ports/python3/python3-3.2.5-4.x86_64/build=/usr/src/debug/python3-3.2.5-4 -fdebug-prefix-map=/usr/src/ports/python3/python3-3.2.5-4.x86_64/src/Python-3.2.5=/usr/src/debug/python3-3.2.5-4 -I/usr/include/libxml2 -I/tmp/pip-build-b8ybku/lxml/src/lxml/includes -I/usr/include/python3.2m -c src/lxml/lxml.etree.c -o build/temp.cygwin-1.7.34-x86_64-3.2/src/lxml/lxml.etree.o -w


src/lxml/lxml.etree.c:8:22: fatal error: pyconfig.h: No such file or directory


compilation terminated.


/usr/lib/python3.2/distutils/dist.py:257: UserWarning: Unknown distribution option: 'bugtrack_url'


warnings.warn(msg)


error: command 'gcc' failed with exit status 1


----------------------------------------
Command "/usr/bin/python3.2m -c "import setuptools, tokenize;__file__='/tmp/pip-build-b8ybku/lxml/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-u3vwj8-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-b8ybku/lxml

我尝试了所有的方法,直到我意识到一个新的cygwin工具链搞乱了python逻辑。cygwin安装一个名为“realgcc”的编译器,它不是真正的 gcc。

解决方案

安装gcc。例:

 apt-cyg install gcc-g++

在Windows上当我试图在Python 3.4中手动安装它时,在windows上有相同的错误。我最终能够通过安装轮子并从Python34目录运行pip来解决这个问题。

1)下载轮从这里:http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml

2) cd Python34\Scripts

3) pip.exe C:\Users\Home\Downloads\lxml- ......... .whl

我使用的是Ubuntu 14.04,这为我解决了这个问题

sudo apt-get build-dep python3-lxml
sudo apt-get install libxml2-dev libxslt-dev python-dev
如果你已经安装了libxml2和libxslt,也许你需要在libxml2和libxslt path到python2.6 include path之间创建一个符号链接。你也可以尝试添加INCLUDE环境参数。 因为gcc命令只搜索这个路径:-I/usr/include/python2.6.

. zip

下面的文件适用于我的windows https://pypi.python.org/pypi/lxml/3.3.3#downloads < / p >

在osx 10.10.5和virtualenv中,也许你可以像下面这样解决这个问题:

sudo C_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2/libxml:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include pip install -r lxml

唯一对我有帮助的是

sudo apt-get install python3.5-dev

在Cygwin上使用Windows 7时,我发现:

Compile failed: command 'gcc' failed with exit status 1
cc -I/usr/include/libxml2 -I/usr/include/libxml2 -c /tmp/xmlXPathInitZsgdMQ.c -o tmp/xmlXPathInitZsgdMQ.o
*********************************************************************************
Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
*********************************************************************************
error: command 'gcc' failed with exit status 1

我通过安装mingw64-x86_64-libxslt来修复它

我用的是Windows电脑。下面是一些用于成功安装lxml的指针(使用python 2.6及更高版本)。

安装以下设备:

  1. MingGW。
  2. Libxml2版本2.7.0或更高版本。
  3. Libxslt版本1.1.23或更高。

所有这些在pip install中都不可用。

libxml2的windows二进制文件被找到在这里

libxslt找到在这里

在你完成上面两个之后,

do: pip install lxml

另一种解决方法是使用来自PyPI的稳定版本或Christoph Gohlke (在这里找到)的非官方Windows二进制文件。

这适用于我,12.04,python2.7.6

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

我知道我要迟到了,

但如果其他方法都不奏效,这也会有所帮助

mkdir ~/tmp
export TMPDIR=~/tmp
STATIC_DEPS=true easy_install-2.7 lxml
设置TMPDIR将确保构建可以运行它需要运行的所有内容,而设置STATIC_DEPS将告诉它拉入自己的libxml2和

. Libxslt2,而不是使用服务器上安装的旧版本
sudo apt install libxslt-dev libxml2-dev

然后尝试升级python setuptools

pip install -U pip setuptools

这应该能解决问题。

我有这个问题与pip安装的lxml。我的CentOS实例使用的是python 2.6,它会抛出这个错误。

为了解决这个问题,我执行了以下操作来运行Python 2.7:

  1. 运行:sudo yum install python-devel
  2. 运行sudo yum install libxslt-devel libxml2-devel
  3. 使用Python 2.7通过/usr/bin/python2.7 YOUR_PYTHON_COMMAND运行您的命令 (对我来说是/usr/bin/python2.7 -m pip install lxml)

我的Linux机器上也出现了同样的错误。如果你去到他们的网站,那也在他们的文档中。所以如果你在Linux机器中得到这种错误,请尝试这些命令,

# apt install libxml2-dev libxslt-dev python-dev

# pip install lxml==3.4.4

Windows:

pip install --upgrade pip wheel
pip install bzt
pip install lxml

这两个包需要分别安装,通常不能使用pip安装…因此,对于FreeBSD:

Download a compressed snapshot of the Ports Collection into /var/db/portsnap:
# portsnap fetch
When running Portsnap for the first time, extract the snapshot into /usr/ports:
# portsnap extract
After the first use of Portsnap has been completed as shown above, /usr/ports can be updated as needed by running:
# portsnap fetch
# portsnap update


Now Install:
cd /usr/ports/textproc/libxml2
make install clean


cd /usr/ports/textproc/libxslt
make install clean

你应该可以出发了……