pip安装lxml错误

这是我的错误:

(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 

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

假设你正在运行一个基于Debian的发行版

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

如果您在基于Debian的发行版上安装Python 3,则还需要安装python3-dev

这对我工作:

 yum install libxslt-devel libxml2-devel 

如果您使用的是Ubuntu / Lubuntu 13.04或Ubuntu 13.10,并且出现“/ usr / bin / ld:找不到-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 

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

你可能需要安装一些软件包,可能是python-dev或者python-devel。

  sudo yum install python-devel 

要么

  sudo aptitude install python-dev 

或者有些。

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

我只运行了512 MB,当我升级到1 GB时,我没有问题。

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

只需安装要求:

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

现在,您可以使用pip软件包pipe理工具来安装它:

 pip install lxml 
 error: command 'gcc' failed with exit status 1 yum remove audit yum install gcc yum install libxslt-devel libxml2-devel cd lxml-xxx python setup.py build python setup.py install 

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

 sudo apt-get build-dep python3-lxml sudo apt-get install libxml2-dev libxslt-dev python-dev 
 STATIC_DEPS=true easy_install lxml 

在Windows上,当在3.3上安装后,在Python 3.4中手动安装时,在窗口上出现了相同的错误。 我终于能够通过安装轮子并从Python34目录运行pip来解决它。

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

2) cd Python34\Scripts

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

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

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

男孩,你应该张贴你的错误日志LANG=C或人不能从你的日志得到真正的原因。 上面的日志说:没有这样的文件或目录。

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

上面的所有答案都假设用户可以访问特权/ root帐户来安装所需的库。 要在本地安装,您需要执行以下步骤。 只显示了概述,因为这些步骤可能会涉及一些问题,具体取决于您可能会丢失的依赖关系

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

2.使用configure将libxml和libxslt的每个安装pathconfiguration为某个本地目录。 防爆。 ./configure --prefix=/home_dir/dependencies/libxslt_path

3.运行然后make install

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

我知道我迟到了,

但是如果没有其他解决办法,这将有所帮助

 mkdir ~/tmp export TMPDIR=~/tmp STATIC_DEPS=true easy_install-2.7 lxml 

设置TMPDIR将确保构build可以运行需要运行的所有内容,并且设置STATIC_DEPS将告诉它将其自己的libxml2和libxslt2,而不是使用服务器上安装的旧版本。

我遇到了这个问题,安装了lxml的pip。 我的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

在Windows 8中使用cygwin 64。

我有…

pip install lxml(…)

 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++ 

这适用于我,12.04,python2.7.6

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

唯一帮助我的是

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

然后尝试升级python setuptools

 pip install -U pip setuptools 

这应该解决它。

我正在使用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 

如果你已经安装了libxml2和libxslt,也许你需要在libxml2和libxsltpath之间build立一个符号链接来包含python2.6path。 你也可以尝试添加INCLUDE环境参数。 因为gcc命令只search这个path:-I / usr / include / python2.6。

下面的文件在windows上为我工作https://pypi.python.org/pypi/lxml/3.3.3#downloads

在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 

我在Windows机器上工作。 这里有一些成功安装lxml的指针(使用python 2.6和更高版本)。

安装以下内容:

  1. MingGW。
  2. libxml2版本2.7.0或更高版本。
  3. libxslt版本1.1.23或更高版本。

所有不在一个pip install

在这里findlibxml2的windows二进制文件。

在这里findlibxslt。

在你完成上述两个之后,

做: pip install lxml

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

与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修复它