'No module named requests' even if I installed requests with pip

In general, you should get into the habit of working in a virtualenv. I find the documentation here to be helpful.

If you install all of your dependencies within the virtual environment, you'll be (mostly) sure that you are installing those deps. in the same environment that you're running the jobs in.

For your case, on the command line go to the directory where your code lives and run

pip install virtualenv
virtualenv my_project
source my_project/bin/activate

Now that the virtualenv is active you can

pip install requests

Only what is installed in the virtualenv will be available. This will keep your system clean. Each project should get its own virtualenv, meaning only the dependencies needed for each project will be available to them. This way you could, say, have version 1 of some dependency installed for one project and version 2 for another. They won't come into conflict.

After you have installed all the dependencies, run

pip freeze > requirements.txt

To get a list of all the dependencies for the project saved. Next time you need to install these, you simply run

pip install -r requirements.txt

Once you are done working in the virtualenv, run

deactivate

I am not 100% sure, but the paths from which python and which pip may indicate that you have two versions installed. The Python version being the old one that was shipped with OS X, and another version.

I would advice you to install Python27 (or even better Python3) from brew.

You can install brew with a single command, and another one for installing Python27/3. When this is done you set the PATH variable in your shell rc file and you should be good to go.

I have Python27 installed (via brew) and my (working environment) reports the following paths:

which python: /usr/local/bin/python
which pip: /usr/local/bin/pip

And

python --version: 2.7.15
pip --version: pip 9.0.1 from /usr/local/lib/python2.7/site-packages (python2.7)

I experienced this same issue on Ubuntu 18.04 LTS, to check that, I first checked if requests library was installed on my system or not.

Run these commands on your terminal inside the virtual environment in which you working

$ python

Then the python command line opens, then run

>>> import requests

After this if you get an ImportError saying, No module named requests, then it means the dependency has not been installed properly. If there is no such error, then it means the dependency is installed successfully.