lxml 本质上什么都没有

发布于 2024-08-19 05:21:56 字数 1290 浏览 3 评论 0原文

Python 的 lxml 包在我的系统上似乎完全损坏了。我不确定问题所在,因为似乎所有文件都已就位。我怀疑问题出在 __init__.py 中,但我没有足够的系统实践来做出准确的诊断或解决问题。

下面是一些我认为有助于诊断问题的代码:

Python 2.6.4 (r264:75706, Dec  7 2009, 18:45:15) 
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import lxml
>>> dir(lxml)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__']
>>> print lxml.__path__
['/usr/lib/python2.6/dist-packages/lxml']
>>> c = open("/usr/lib/python2.6/dist-packages/lxml/__init__.py", "r")
>>> for line in c:
...     print line
... 
# this is a package



>>> c.close()
>>> import os
>>> os.system("ls /usr/lib/python2.6/dist-packages/lxml/")
builder.py      ElementInclude.py   __init__.py    sax.pyc
builder.pyc     ElementInclude.pyc  __init__.pyc       usedoctest.py
cssselect.py        _elementpath.py objectify.so       usedoctest.pyc
cssselect.pyc       _elementpath.pyc    pyclasslookup.py
doctestcompare.py   etree.so        pyclasslookup.pyc
doctestcompare.pyc  html        sax.py
0
>>> 

就像我说的,我怀疑 __init__.py 包含问题,但我不能 100% 确定。

另外,我正在使用 Linux Mint 8 - 大致相当于 Ubuntu 9.10。

提前致谢。

The lxml package for Python seems to absolutely broken on my system. I am not sure of the problem, as all of the files are in place, it seems. My suspicion is that the problem is in __init__.py, but I don't have enough practice with the system to make an accurate diagnosis or fix the problem.

Here is some code that I think will help diagnose the problem:

Python 2.6.4 (r264:75706, Dec  7 2009, 18:45:15) 
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import lxml
>>> dir(lxml)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__']
>>> print lxml.__path__
['/usr/lib/python2.6/dist-packages/lxml']
>>> c = open("/usr/lib/python2.6/dist-packages/lxml/__init__.py", "r")
>>> for line in c:
...     print line
... 
# this is a package



>>> c.close()
>>> import os
>>> os.system("ls /usr/lib/python2.6/dist-packages/lxml/")
builder.py      ElementInclude.py   __init__.py    sax.pyc
builder.pyc     ElementInclude.pyc  __init__.pyc       usedoctest.py
cssselect.py        _elementpath.py objectify.so       usedoctest.pyc
cssselect.pyc       _elementpath.pyc    pyclasslookup.py
doctestcompare.py   etree.so        pyclasslookup.pyc
doctestcompare.pyc  html        sax.py
0
>>> 

Like I said, my suspicion is that __init__.py contains the problem, but I'm not 100% sure.

Also, I'm using Linux Mint 8 - the rough equivalent of Ubuntu 9.10.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

温折酒 2024-08-26 05:21:56

不,你只是做错了!例如,尝试from lxml import etree,您应该能够完全使用etreeimport lxml——导入! -- 是否让您隐式访问任何包的模块!-)

No, you're just doing it wrong! Try, e.g., from lxml import etree, and you should be able to use etree fully. import lxml -- importing the package! -- does not give you implicit access to any of the package's modules!-)

燕归巢 2024-08-26 05:21:56

我认为所有 lxml 代码都在子包中。尝试

from lxml import etree

I think all the lxml code is in subpackages. Try

from lxml import etree
水染的天色ゝ 2024-08-26 05:21:56

__init__.py 文件中没有任何内容是完全正常的: http://docs.python.org/tutorial/modules.html#packages

该文件只是让 Python 知道它是一个包,而不仅仅是一个包含一堆模块的目录。

您只需直接导入包内的模块即可。

from lxml import etree, html

ETC...

It's perfectly normal for a __init__.py file to have nothing in it: http://docs.python.org/tutorial/modules.html#packages

The file is just there to let Python know that it's a package and not just a directory with a bunch of modules in it.

You just need to import the modules inside the package directly.

from lxml import etree, html

etc...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文