lxml包引入错误

时间:2023-03-09 01:04:28
lxml包引入错误

在使用第三方包lxml引入etree模块时报错:

  1. >>> from lxml import etree
  2. Traceback (most recent call last):
  3. File "<stdin>", line 1, in ?
  4. ImportError: dynamic module does not define init function (initetree)

由于之前安装是直接使用源码包进行安装,报错之后决定卸载掉源码安装的版本(直接删除site-packages目录下面的lxml包文件),然后重新使用easy_insall命令安装,安装过程中报错信息如下:

  1. ERROR: /bin/sh: xslt-config: command not found
  2. ** make sure the development packages of libxml2 and libxslt are installed **

于是分别安装libxml2 and libxslt模块:

  1. 1027  yum install libxml2
  2. 1028  yum install libxslt

检查xslt-config命令是否安装成功:

  1. [root@oser623 mongodb]# whereis xslt-config
  2. xslt-config:
  3. [root@oser623 mongodb]#

xslt-config命令还是不存在,在网上找了找资料,提示说需要安装 libxslt-devel

  1. 1033  yum install libxslt-devel

现在再来尝试安装 lxml模块

  1. [root@oser623 mongodb]# whereis xslt-config
  2. xslt-config: /usr/bin/xslt-config
  3. [root@oser623 mongodb]# easy_install lxml
  4. Searching for lxml
  5. Reading http://pypi.python.org/simple/lxml/
  6. Reading http://codespeak.net/lxml
  7. Best match: lxml 2.3.4
  8. Downloading http://lxml.de/files/lxml-2.3.4.tgz
  9. Processing lxml-2.3.4.tgz
  10. Running lxml-2.3.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-zdolOV/lxml-2.3.4/egg-dist-tmp-QQHSfi
  11. Building lxml version 2.3.4.
  12. Building without Cython.
  13. Using build configuration of libxslt 1.1.17
  14. Building against libxml2/libxslt in the following directory: /usr/lib64
  15. Adding lxml 2.3.4 to easy-install.pth file
  16. Installed /usr/lib/python2.4/site-packages/lxml-2.3.4-py2.4-linux-x86_64.egg
  17. Processing dependencies for lxml
  18. Finished processing dependencies for lxml

包导入测试:

  1. [root@oser623 mongodb]# python
  2. Python 2.4.3 (#1, Feb 22 2012, 16:05:45)
  3. [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>> from lxml import etree
  6. >>>

安装成功!