ImportError:无法从“ requests_html”

时间:2019-03-25 13:43:07

标签: python-3.x python-requests-html

当我尝试通过其网站示例使用新模块 requests_html 时,我发现控制台在标题中显示了信息。

  • 我已经使用pip install requests_html
  • 成功安装了 requests_html
  • 我已将python更新为python3.7(64位)

控制台消息:

Traceback (most recent call last):
  File "C:/Users/owlish/PycharmProjects/python34/requests.py", line 2, in <module>
    from requests_html import HTMLSession
  File "C:\Users\owlish\AppData\Local\Programs\Python\Python37\lib\site-packages\requests_html.py", line 10, in <module>
    import requests
  File "C:\Users\owlish\PycharmProjects\python34\requests.py", line 2, in <module>
    from requests_html import HTMLSession
ImportError: cannot import name 'HTMLSession' from 'requests_html' (C:\Users\owlish\AppData\Local\Programs\Python\Python37\lib\site-packages\requests_html.py)

代码:

from requests_html import HTMLSession
session = HTMLSession()
r = session.get('https://python.org/')

我希望它能正常工作,例如示例https://html.python-requests.org/

1 个答案:

答案 0 :(得分:1)

在AhmedHawary的帮助下,我找到了错误的原因:我有一个名为 requests.py 的文件,该文件与 keywords 冲突。重命名文件名后,它运行良好。