我将centos6.7上的python更新为python2.7.3,并将新版本作为默认版本。然后我使用sudo yum install python-lxml
来安装python-lxml。显示
package python-lxml-2.2.3-1.1.el6.x86_64 has been installed and is the newest,there is nothing to do
但当我使用python(默认2.7.3)python
和import lxml
时,错误如下ImportError:没有名为lxml的模块。然而,当我使用像/usr/bin/python2.6
和import lxml
这样的旧版本python时,不会发生任何错误。lxml适用于旧版本的python。
怎么了?
我尝试了许多其他方法:
1.使用pip安装lxml sudo /usr/local/bin/pip install lxml
,但发生错误
src/lxml/lxml.etree.c:237975: error:expected ‘)’ before ‘value’
Compile failed: command 'gcc' failed with exit status 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 "import
setuptools;__file__='/home/zhoulipeng/software/lxml-3.4.4/build/lxml/setup.py';exec(compile(open(__file__).read().replace('rn', 'n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-VIpDJ1-record/install-record.txt failed with error code 1
4
似乎没有安装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 ')'before'__pyx_f_4lxml_5etree_xslt_doc_loader'
error: command 'gcc' failed with exit status 1
有人能帮我吗?非常感谢。
百胜在pythons 2.6路径中安装了lxml。您需要为python 2.7搜索rpm或构建自己的rpm。
如果提供python 27的人也为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
>>>