Modules are installed using pip on OSX but not found when importing

Here the answer that worked, which is basically what has been explained in the comments of the question. However, I thought it would be useful to have it explained as a clear and well structured answer.

As highlighted, the problem was that I was not using the interpreter that pip was installing for.
The command which shows where pip was installing the modules:

$ which -a pip
/usr/local/bin/pip

and where the different python versions were located:

$ which -a python
/usr/bin/python
/usr/local/bin/python

That is, my system/default python was

/usr/bin/python

while pip was installing for

/usr/local/bin/python

Therefore, I could not import anything I installed when I just typed python, because the /usr/bin/python interpreter was the one started.

Solution

Install pip again specifying the destination of the modules that will be installed. This must be the destination for the system/default python.

This has been done in two steps:

  1. Downloding get-pip.py from bootstrap.pypa.io/get-pip.py. (You may need to use the deprecated one for Python 2: bootstrap.pypa.io/2.7/get-pip.py)

  2. Installing it with the following command

    sudo /usr/bin/python get-pip.py

Note that without the sudo I got an error and was not able to install pip.

Leave a Comment