我试图在Fedora服务器上运行一个python脚本。我得到以下错误。
/usr/bin/python report_generation.py
Traceback (most recent call last):
File "report_generation.py", line 9, in ?
import lxml.html
ImportError: No module named lxml.html
做了一些研究,我发现它需要python lxml包来运行脚本。这台机器已经安装了一些lxml。但是,我做不到。
yum search libxml
libxml2.i386 : Library providing XML and HTML support
libxml2.x86_64 : Library providing XML and HTML support
libxml2-devel.i386 : Libraries, includes, etc. to develop XML and HTML applications
libxml2-devel.x86_64 : Libraries, includes, etc. to develop XML and HTML applications
libxml2-python.x86_64 : Python bindings for the libxml2 library
libxslt.i386 : Library providing the Gnome XSLT engine
libxslt.x86_64 : Library providing the Gnome XSLT engine
libxslt-devel.i386 : Libraries, includes, etc. to embed the Gnome XSLT engine
libxslt-devel.x86_64 : Libraries, includes, etc. to embed the Gnome XSLT engine
libxslt-python.x86_64 : Python bindings for the libxslt library
而且,它还说当我试图安装这些软件包时,它们都是最新的。出于某种原因,它没有在运行脚本时提取lxml模块并抛出此错误。 我对Linux和Python都是新手。请为我提供调试此问题的任何线索。
需要将
lxml
包与您安装的任何libxml
库分开安装。使用pip install lxml
(可选前缀为sudo
进行全局安装)来安装它。或者
看看^{} 包,很明显它是
libxml2
的常用Python绑定,而不是第三方lxml
绑定。这些都是而不是相同的东西,它们是完全分开维护的。正如the docs所说:
你怎么知道
libxml2-python
是前者而不是后者?嗯,链接是指向http://xmlsoft.org,而不是指向http://lxml.de。如果你看一下files,它会安装名称类似libxml2.py
,而不是lxml
的东西。所以,您不能导入lxml,因为您没有安装lxml。
根据rpmfind,有用于各种发行版的^{} 包。如果有一个适合你的,只要安装它,而不是(或者另外,如果你两者都想要的话)安装
libxml2-python
。如果不是,您可能需要用^{} 安装它。假设您已经安装了
pip
,请执行以下操作:相关问题 更多 >
编程相关推荐