lxml 本质上什么都没有
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,你只是做错了!例如,尝试
from lxml import etree
,您应该能够完全使用etree
。import lxml
——导入包! -- 是否不让您隐式访问任何包的模块!-)No, you're just doing it wrong! Try, e.g.,
from lxml import etree
, and you should be able to useetree
fully.import lxml
-- importing the package! -- does not give you implicit access to any of the package's modules!-)我认为所有 lxml 代码都在子包中。尝试
I think all the lxml code is in subpackages. Try
__init__.py
文件中没有任何内容是完全正常的: http://docs.python.org/tutorial/modules.html#packages该文件只是让 Python 知道它是一个包,而不仅仅是一个包含一堆模块的目录。
您只需直接导入包内的模块即可。
ETC...
It's perfectly normal for a
__init__.py
file to have nothing in it: http://docs.python.org/tutorial/modules.html#packagesThe 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.
etc...