在使用第三方包lxml引入etree模块时报错:
[python] view plain copy
- >>> 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命令安装,安装过程中报错信息如下:
[sql] view plain copy
- ERROR: /bin/sh: xslt-config: command not found
- ** make sure the development packages of libxml2 and libxslt are installed **
于是分别安装libxml2 and libxslt模块:
[sql] view plain copy
- 1027 yum install libxml2
- 1028 yum install libxslt
检查xslt-config命令是否安装成功:
[sql] view plain copy
- [[email protected] mongodb]# whereis xslt-config
- xslt-config:
- [[email protected] mongodb]#
xslt-config命令还是不存在,在网上找了找资料,提示说需要安装 libxslt-devel
[sql] view plain copy
- 1033 yum install libxslt-devel
现在再来尝试安装 lxml模块
[sql] view plain copy
- [[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
包导入测试:
[sql] view plain copy
- [[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
- >>>
安装成功!
时间: 2024-10-03 22:51:17