lxml包引入错误
Posted Chen Jian
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了lxml包引入错误相关的知识,希望对你有一定的参考价值。
在使用第三方包lxml引入etree模块时报错:
- >>> from lxml import etree
- Traceback (most recent call last):
- File "<stdin>", line 1, in ?
- ImportError: dynamic module does not define init function (initetree)
由于之前安装是直接使用源码包进行安装,报错之后决定卸载掉源码安装的版本(直接删除site-packages目录下面的lxml包文件),然后重新使用easy_insall命令安装,安装过程中报错信息如下:
- ERROR: /bin/sh: xslt-config: command not found
- ** make sure the development packages of libxml2 and libxslt are installed **
于是分别安装libxml2 and libxslt模块:
- 1027 yum install libxml2
- 1028 yum install libxslt
检查xslt-config命令是否安装成功:
- [[email protected] mongodb]# whereis xslt-config
- xslt-config:
- [[email protected] mongodb]#
xslt-config命令还是不存在,在网上找了找资料,提示说需要安装 libxslt-devel
- 1033 yum install libxslt-devel
现在再来尝试安装 lxml模块
- [[email protected] mongodb]# whereis xslt-config
- xslt-config: /usr/bin/xslt-config
- [[email protected] mongodb]# easy_install lxml
- Searching for lxml
- Reading http://pypi.python.org/simple/lxml/
- Reading http://codespeak.net/lxml
- Best match: lxml 2.3.4
- Downloading http://lxml.de/files/lxml-2.3.4.tgz
- Processing lxml-2.3.4.tgz
- Running lxml-2.3.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-zdolOV/lxml-2.3.4/egg-dist-tmp-QQHSfi
- Building lxml version 2.3.4.
- Building without Cython.
- Using build configuration of libxslt 1.1.17
- Building against libxml2/libxslt in the following directory: /usr/lib64
- Adding lxml 2.3.4 to easy-install.pth file
- Installed /usr/lib/python2.4/site-packages/lxml-2.3.4-py2.4-linux-x86_64.egg
- Processing dependencies for lxml
- Finished processing dependencies for lxml
包导入测试:
- [[email protected] mongodb]# python
- Python 2.4.3 (#1, Feb 22 2012, 16:05:45)
- [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
- Type "help", "copyright", "credits" or "license" for more information.
- >>> from lxml import etree
- >>>
安装成功!
以上是关于lxml包引入错误的主要内容,如果未能解决你的问题,请参考以下文章
lxml安装期间出现python gcc和setuptools错误
windows 8.1中 Python无法安装lxml库的解决方案
使用 lxml 和请求进行 HTML 抓取会产生 unicode 错误 [重复]
UI进阶 XML解析适配 引入GDataXML文件时候 'libxml/tree.h'file not found 错误解决办法