python - 在 python 中安装 lxml 模块

标签 python lxml python-import

在运行 python 脚本时,我得到了这个错误

  from lxml import etree
ImportError: No module named lxml

现在我尝试安装 lxml

sudo easy_install lmxl

但它给了我以下错误

Building lxml version 2.3.beta1.
NOTE: Trying to build without Cython, pre-generated 'src/lxml/lxml.etree.c' needs to be available.
ERROR: /bin/sh: xslt-config: not found

** make sure the development packages of libxml2 and libxslt are installed **

使用 libxslt 的构建配置

src/lxml/lxml.etree.c:4: fatal error: Python.h: No such file or directory
compilation terminated.
error: Setup script exited with error: command 'gcc' failed with exit status 1

最佳答案

只要做:

sudo apt-get install python-lxml

对于 Python 2(例如,Inkscape 需要):

sudo apt-get install python2-lxml

如果您打算从源代码安装,那么 albertov's answer会有所帮助。但除非有原因,否则不要,直接从存储库安装它。

关于python - 在 python 中安装 lxml 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4598229/

相关文章:

python - django ldap auth 无法从应用程序运行

python - 如何在一个GUI中显示两个或更多视频流

python - 如何找到哪个文件是 "initiator"Python

python - 即使在使用 strip_cdata=False 后 CDATA 在 lxml 中被剥离

python - 如何在lxml中找到元素的直接子元素

python - 从(或附近)具有相同名称的脚本导入库会引发 "AttributeError: module has no attribute"或 ImportError 或 NameError

python - 在 __init__.py 和 'import as' 语句中导入

python - 具有多个键和多个属性的 JSON 类

具有不相关进程的 Python 多处理

python - 如何使用 Python LXML Objectify 创建相同的 XML 元素 3 次