libpml使用pip安装错误

问题描述 投票:254回答:26

这是我的错误:

(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
python lxml pip
26个回答
466
投票

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

lxml documentation开始,假设您运行的是基于Debian的发行版:

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

对于基于Debian的系统,应该足以安装python-lxmlpython3-lxml的已知构建依赖关系,例如:

sudo apt-get build-dep python3-lxml

5
投票
STATIC_DEPS=true easy_install lxml

4
投票

安装lxml二进制文件就可以了。 Check this


3
投票

我有一个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

3
投票
sudo apt install libxslt-dev libxml2-dev

然后尝试升级python setuptools

pip install -U pip setuptools

这应该解决它。


2
投票

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

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

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


2
投票

上述所有答案都假定用户可以访问特权/ root帐户来安装所需的库。要在本地安装它,您需要执行以下步骤。仅显示概述,因为根据您可能缺少的依赖性,步骤可能会涉及一些

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

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

3.Run make然后make install

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


2
投票

这适用于我,12.04,python2.7.6

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

2
投票

我知道我迟到了

但如果没有别的办法,这将有所帮助

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

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


1
投票

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

1
投票

唯一对我有帮助的是

sudo apt-get install python3.5-dev

104
投票

这对我有用:

yum install libxslt-devel libxml2-devel

1
投票

我在我的Linux机器上遇到了同样的错误。如果你去他们的文档中的website那么。如果你在Linux机器上遇到这种错误,请试试这些命令,

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

# pip install lxml==3.4.4


0
投票

我使用的是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

0
投票

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


0
投票

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


0
投票

在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

0
投票

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

安装以下内容:

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

所有这些都不在pip install上。

找到了libxml2的windows二进制文件here

libxslt被发现here

完成上述两项后,

做:pip install lxml

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


0
投票

使用Windows 7和Cygwin,我遇到了:

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


75
投票

如果您使用的是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

33
投票

不,你错过了Python头文件。当您使用系统Python时,这主要发生在Linux上(有reasons not to do that,但这是一个不同的问题)。

你可能需要安装一些软件包,它可能叫做python-dev或python-devel。

 sudo yum install python-devel

要么

 sudo aptitude install python-dev

或者某些人。


9
投票

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

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

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


8
投票

在Windows上,我在3.3上安装后尝试在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


7
投票

只是安装要求:

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

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

pip install lxml

6
投票
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

6
投票

我正在使用Ubuntu 14.04,这解决了我的问题

sudo apt-get build-dep python3-lxml
sudo apt-get install libxml2-dev libxslt-dev python-dev
© www.soinside.com 2019 - 2024. All rights reserved.