我在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