我在mac上安装了lxml并试图在我的代码中使用它,并且导入了tostring和tounicode错误。 Python根本看不到它。任何想法我做错了什么?lxml.etree中未解决的导入tostring
这是导致问题的代码 - 我得到一个未解决的导入错误
而且我的IDE(日蚀)是能够看到LXML的初始化 .py文件
from lxml.etree import tostring
from lxml.etree import tounicode
。 etree模块。这是它看到的---
# this is a package
def get_include():
"""
Returns a list of header include paths (for lxml itself, libxml2
and libxslt) needed to compile C code against lxml if it was built
with statically linked libraries.
"""
import os
lxml_path = __path__[0]
include_path = os.path.join(lxml_path, 'includes')
includes = [include_path, lxml_path]
for name in os.listdir(include_path):
path = os.path.join(include_path, name)
if os.path.isdir(path):
includes.append(path)
return includes
感谢您的任何帮助。
编辑:
中仅有的日志我看到的是 未解决进口:的toString 未解决进口:tounicode
当我的ToString它的导入前添加以下行工作没有错误 - 从 进口etree lxml
也给你一些我想要做的更多背景。我从这里得到了可读性代码(https://github.com/buriy/python-readability),并试图在我的项目中使用它。
编辑2:我解决了这个问题,但仍然不明白为什么。我想直接使用可读性项目中的代码,而无需使用easy_install安装软件包。这个想法是进入代码,以便我明白它在做什么。但是当我将代码复制到我的项目中时,我在可读性代码中得到了上述错误。如果我使用easy_install安装软件包,那么我只需导入通过可读性导出的类并使用它。
因此,有人可以告诉我直接使用代码和安装软件包有何区别吗?什么是.egg文件?如何创建一个?
你能够导入_just_'lxml'吗?你能发布你看到的完整例外吗? –
@ dan.lococq - 我编辑了我的问题并添加了更多信息。是的,我能够导入lxml – R11