Search code examples
python-3.xpython-requests-html

ImportError: cannot import name 'HTMLSession' from 'requests_html'


When I tried to use the new module requests_html using the example of its website,I found the console displays information in the title.

  • I have successfully installed requests_html using pip install requests_html
  • I have updated the python to python3.7 (64-bit)

The messages of console:

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)

code:

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

I expect it to work without an error,like the examples https://html.python-requests.org/.


Solution

  • With AhmedHawary's help,I found the reason for the error:I had a file named requests.py , which confilcted with the keywords . It worked fine after I renamed the file name.