python - 在 CentOS 6.7 版(最终版)上导入 lxml 失败

标签 python gcc centos lxml

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

package python-lxml-2.2.3-1.1.el6.x86_64 已经安装,是最新的,没有什么可做的

但是当我使用python(默认2.7.3)pythonimport lxml时,出现如下错误 ImportError: No module named lxml .However 当我使用像/usr/bin/python2.6import lxml 这样的旧版本python 时,没有错误发生。 lxml 适用于旧版本的 python。

有什么问题?

我尝试了很多其他方法:

1. 使用pip安装lxml sudo/usr/local/bin/pip install lxml 但是出现错误

src/lxml/lxml.etree.c:237975: 错误:'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

命令/usr/bin/python -c "import setuptools;__file__='/home/zhoulipeng/software/lxml-3.4.4/build/lxml/setup.py';exec(compile(open(__file__).read().replace('\r\n ', '\n'), __file__, 'exec'))"install --single-version-externally-managed --record/tmp/pip-VIpDJ1-record/install-record.txt 失败,错误代码为 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' 错误:命令“gcc”失败,退出状态为 1

有人可以帮助我吗?谢谢。

最佳答案

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

关于python - 在 CentOS 6.7 版(最终版)上导入 lxml 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33819268/

相关文章:

c - 双重编译 C 代码以减少执行时间

linux - NPM 无法全局安装 browserify

php - 尽管时区有效,但设置默认时区不起作用

python - Revit API 2015 Python : GetAllViewports() takes exactly 1 argument (0 given)

python - 在 django 应用程序中将数据存储在内存中是一种好习惯吗?

python - 是否可以在 App Engine 中缓存 json 结果?

c - 头文件未正确包含

python - 如何用Python求数据集每一列的熵?

c - 使用 ASM 函数覆盖弱 C 函数别名

Cassandra 查询结果各不相同