Python CentOS 6.7版(最终版)导入lxml失败

Python CentOS 6.7版(最终版)导入lxml失败,python,gcc,centos,lxml,Python,Gcc,Centos,Lxml,我将centos6.7上的python更新为python2.7.3,并将新版本作为默认版本。然后我使用sudo-yum-install-python-lxml来安装python-lxml。它表明 包python-lxml-2.2.3-1.1.el6.x86_64已经安装,并且是最新的,无需执行任何操作 但是当我使用python(默认的2.7.3)python和importlxml时,会发生如下错误 。但是,当我使用较旧版本的python时,如/usr/bin/python2.6和import l

我将centos6.7上的python更新为python2.7.3,并将新版本作为默认版本。然后我使用
sudo-yum-install-python-lxml
来安装python-lxml。它表明

包python-lxml-2.2.3-1.1.el6.x86_64已经安装,并且是最新的,无需执行任何操作

但是当我使用python(默认的2.7.3)
python
importlxml
时,会发生如下错误 。但是,当我使用较旧版本的python时,如
/usr/bin/python2.6
import lxml
,不会发生错误。lxml适用于较旧版本的python

有什么问题吗

我尝试了许多其他方法:

1.使用pip安装lxml
sudo/usr/local/bin/pip安装lxml
,但会发生错误

src/lxml/lxml.etree.c:237975:error:expected')在“value”之前

编译失败:命令“gcc”失败,退出状态为1

cc -I/usr/include/libxml2 -I/usr/include/libxml2 -c 
/tmp/xmlXPathInitB69jpu.c-o tmp/xmlXPathInitB69jpu.o

/tmp/xmlXPathInitB69jpu.c:1:26: error:libxml/xpath.h: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/usr/bin/python-c“导入”
setuptools;uuuu file_uuuu='/home/zhoulipeng/software/lxml-3.4.4/build/lxml/setup.py';exec(编译(打开(uuu file.read().replace('\r\n','\n'),uuuu file.exec'))安装--外部管理的单一版本--record/tmp/pip-VIpDJ1-record/install-record失败,错误代码为1

似乎没有安装libxml2,所以我安装了所有依赖项,
sudo-yum-install-libxml2-devel-libxslt-devel-python-devel
,它显示:

package libxml2-devel-2.7.6-20.el6.x86_64 has been installed and is the newest
package libxslt-devel-1.1.26-2.el6_3.1.x86_64 has been installed and is the newest
package python-devel-2.6.6-64.el6.x86_64 has been installed and is the newest
这意味着我已经安装了libxml2包

2.从源代码安装lxml

当我用
sudo python setup.py build
构建源代码时,它失败了
src/lxml/lxml.etree.c:201156:error:expected')在“\uuuupyx\uf\u4lxml\u5etree\uxslt\udoc\uloader”之前
错误:命令“gcc”失败,退出状态为1

cc -I/usr/include/libxml2 -I/usr/include/libxml2 -c 

有人能帮我吗?谢谢。

百胜在pythons 2.6路径中安装了lxml。您需要为Python2.7搜索rpm或构建自己的rpm

如果提供Python27的人也为lxml构建了rpm的话

如果您通过redhat的软件集合安装了python27,您还可以尝试:

yum install python27-python-pip -y
scl enable python27 bash
pip install lxml

# python
Python 2.7.8 (default, Jun  9 2015, 19:27:51)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import lxml
>>>

不要弄乱CentOS/RedHat系统上的默认系统python。您只会导致可怕的问题(包括完全中断
yum
。不同的python版本在不同的位置查找模块。这些包都是为CentOS 6版python(2.6.6)构建的。您的python看起来不在相同的位置。因此,如果我希望lxml与更新的python版本2.7.3(默认)一起工作,我应该怎么做?现在lxml可用于较旧的python2.6,但不能用于更新的python2.7.3。谢谢。您可以使用您的python版本手动安装python模块,而不使用任何系统软件包。您还应该查看python软件集合库(SCL)因为它们可能以正式打包的方式提供了您想要的内容。好吧,我尝试从源代码安装lxml。由于python的默认版本是更新的版本2.7.3,所以我使用“sudo python setup.py build”,但出现错误“command'gcc'failed with exit status 1”(如前所述)。但是,centos服务器中已经安装了gcc,所以现在我不知道我能做什么(当使用“pip”时,也会发生错误)。稍后我将检查python软件集合库,谢谢。您确定安装了
gcc
?因为它看起来不像(或者其他一些东西出了很大问题)。您能否运行
gcc--help
并正确获取帮助输出?在哪里安装了
gcc
?command-vgcc
说了什么?在
sudo
下的
$PATH
是什么?(即
sudo'echo$PATH'
输出是什么?)对不起,但我不清楚“您需要为Python2.7搜索rpm或构建自己的rpm",我试图从源代码构建lxml,但失败了。谢谢。好的,这是我试图告诉您,您需要来自构建和分发python 2.7 rpm的人的rpm。如果您没有rpm,我们可以尝试构建rpm。首先,您是如何安装较新版本的python的?来自RedHat scl repos?我从源代码构建较新版本的python代码,并将较新版本设置为默认版本。当我在shell中键入“python”时,它会显示我安装的python的版本。您为什么不使用python27的官方软件包?当我使用“yum install python27 python pip-y”时,它会显示:没有可用的python27 python pip包。我该怎么办?