Python module not found even though "Requirement Already satisfied in Pip"

110,348

Solution 1

Run in command prompt.

pip list

Check what version you have installed on your system if you have an old version.

Try to uninstall the package...

pip uninstall requests

Try after to install it:

pip install requests

You can also test if pip does not do the job.

easy_install requests

Solution 2

In my case, I was running a python version included with Jupyter, which installs modules in a different place than the default one apparently. I found that out by running this in Jupyter:

import sys
sys.executable

which gave me

'/usr/local/Cellar/jupyterlab/3.0.13/libexec/bin/python3.9'

I was then able to run the following command in Jupyter:

!/usr/local/Cellar/jupyterlab/3.0.13/libexec/bin/python3.9 -m pip install scipy matplotlib

and then I was able to import my modules:

import scipy.stats
import matplotlib

Solution 3

i had the same issue(also in MAC OS) and solved it by instead running the python script with python3: python3 script.py

in my case i was also using pip3 and not pip.

Solution 4

I suffered from this problem and finally found the solution.

Defaulting to user installation because normal site-packages is not writeable

Requirement already satisfied: django in /usr/lib/python3/dist-packages (2.2.12)

use 'sudo' to crossoff user installation issue;

and pip install --target=/usr/local/python3.7/site-packages --upgrade {module_name}

someone mentioned this and worked for me.

Solution 5

If you are using a Mac, it could be that you installed the modules with pip (meaning python2, but you execute your code with python3 which does not have the modules you installed for python2).

Mac has python version 2 set as default and usually does not come with pip preinstalled or is linked with version 2. I recommend leaving it that way. Use version 3 for your personal use cases and leave your Mac with version 2 as default. As you have to install python3 yourself, means you might also want to check/install pip3.

Check if you have python 3 installed:

python3 --version

Check if you have pip3 installed (usually included by default since python 3.4):

pip3 --version

Check what packages you have installed with pip3:

pip3 list

If you use an editor tool, make sure to set it to use python3 when running your file.

Example for VS Code: Set VS Code to use Python3 on the bottom right corner, which you should see when having a .py file open: Set Python version

And now if you want to import any modules into python, make sure to install them with pip3:

pip3 install package_name

If you run into permission issue, you might consider to run the command with sudo rights:

sudo pip3 install package_name
Share:
110,348
zoey cluff
Author by

zoey cluff

Updated on December 10, 2021

Comments

  • zoey cluff
    zoey cluff over 2 years

    writing some python in OS X, and it's saying several packages I installed with pip "ImportError: no module named requests"

    When running pip install requests

    > sudo -H pip install requests 
    Requirement already satisfied: requests in /usr/local/lib/python2.7/site-packages 
    Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python2.7/site-packages (from requests) 
    Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python2.7/site-packages (from requests) 
    Requirement already satisfied: urllib3<1.22,>=1.21.1 in /usr/local/lib/python2.7/site-packages (from requests) 
    Requirement already satisfied: idna<2.6,>=2.5 in /usr/local/lib/python2.7/site-packages (from requests)
    

    it's erroring on twindb_cloudflare, requests, group, tarutil, and MySQL DB. I'm able to run the exact same imports on another script (in the same folder) without error.