"ImportError: No module named requests_html" after installing requests-html to pip and pip3

3.6k views Asked by At

Tried installing requests-html through pip and pip3 in many different ways (recommendations from other StackOverflow threads) and I keep on getting the same error ImportError: No module named requests_html.

Checked pip and pip3 list, both of them have requests and requests-html. Also my python is updated, its 3.7.6.

Also weirdly I started writing the code on jupyter notebook, and everything worked, however when I switched to sublime text that's where the problem occurred.

Please help.

P.s. I am on a mac, and I am a beginer.

3

There are 3 answers

0
lax48 On BEST ANSWER

The issue where Sublime was using the wrong Python Environment.

You need to add a new build configuration:

  1. Check where is your Python3 path (using which or where commands, depending on your os)
  2. Add and configure the build system (look at the link below or google how to do it)
  3. Select the newly created build system

Source: https://medium.com/@hariyanto.tan95/set-up-sublime-text-3-to-use-python-3-c845b742c720

0
rahoo On

I am no Mac expert but.. I know Mac has its own python2 and 3 inner versions which is critical for the OS to operate, so you maybe installed pip into those ones instead of the ones you are operating via PATH.

2
Hocli On

I recommend trying everything in command line.

MacOS is based on Unix and it is very command line friendly.

I also recommend working with Python virtual envs, so create a virtual env and then install what you need there.

Go to a folder where you want to create the Python virtualenvs, and create a virtualenv called learn for example, then install requests_html in there:

mkdir ~/venvs
cd ~/venvs
python3 -m venv learn

source learn/bin/activate
learn/bin/pip install requests-html

Then when running your project, make sure you have that virtual env activated

source learn/bin/activate

It is useful at this stage to confirm if the python program used is the one from your virtual env so try

which python
which python3

And let us know the answer. Ideally either python or python3 is the one from within the virtualenv. Then, with the good one, try:


python myproject.py

You got the import correctly, it should be in your file, myproject.py

import requests_html