Python 3.4 导入错误:无法导入名称';html';

Python 3.4 导入错误:无法导入名称';html';,python-3.4,Python 3.4,我运行此python代码,并使用以下命令在windows上导入lxml库: Path > install setup.py 它已成功安装 代码是: from lxml import html import requests page = requests.get('http://econpy.pythonanywhere.com/ex/001.html') tree = html.fromstring(page.text) #This will create a list of buy

我运行此python代码,并使用以下命令在windows上导入lxml库:

Path > install setup.py
它已成功安装

代码是:

from lxml import html
import requests
page = requests.get('http://econpy.pythonanywhere.com/ex/001.html')
tree = html.fromstring(page.text)

#This will create a list of buyers:
buyers = tree.xpath('//div[@title="buyer-name"]/text()')

#This will create a list of prices
prices = tree.xpath('//span[@class="item-price"]/text()')
print ('Buyers: ', buyers)
print ('Prices: ', prices)
但当我运行此代码时,会出现以下错误:

ImportError: cannot import name 'html'

您需要安装html包…请检查此url


我有一台Mac电脑,正在使用Anaconda分发版。当我尝试导入HTML时,出现了一个错误:

>>> from html import HTML
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name HTML
文件
html.py
和目录
html-1.16.dist info/
是正确的内容。我不知道
html/
目录是如何到达那里的。我删除了“html/”,因此现在我有:

drwxr-xr-x    9 user.name  staff     288 Feb 26 14:15 html-1.16.dist-info/
-rw-r--r--    1 user.name  staff   19209 Feb 26 14:15 html.py
-rw-r--r--    1 user.name  staff   24206 Feb 26 14:15 html.pyc
导入语句现在可以工作了:

>>> from html import HTML
>>>  

您的windows上安装了两个版本的python吗?请检查sys.path以确保安装模块的目录在其中,否则您必须添加它(google PYTHONPATH windows提供了一些帮助。)没有只安装python3.4版本。抱歉,这不是答案!问题不在于安装软件包,而是在安装后使用它。工作顺利。谢谢。我的mac osx也有同样的问题。这个解决方案非常有效。如果有帮助的话,我的
网站包
目录中还有两个文件(
html5lib
html5lib-1.0.1.dist info
),我也删除了它们,最后得到了与答案中提到的完全相同的三个文件。
>>> from html import HTML
>>>