zoey cluff
zoey cluff

Reputation: 703

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

Python is 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. [Note: I'm running on OS X]

Upvotes: 54

Views: 308845

Answers (18)

Geographos
Geographos

Reputation: 1466

I had a similar problem, but in my case, none of the answers above worked. The reason behind it is probably Windows 11.

enter image description here

Despite "listed" and "requirement already satisfied" the IDLE couldn't load the library at all.

I've repeated the installation process in the same manner for the other directory

\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0>pip install openpyxl

and it started working!

enter image description here

I believe the reasonable way could be the installation of a Python library both in the standard folder discussed widely on the web as well as in the directory shown here in the situation when you are a Windows 11 user.

Upvotes: 0

San
San

Reputation: 1

I had this problem, and it was caused by having python installed both from the Microsoft store and python's installer. I fixed it by uninstalling the Microsoft store version in "Add or remove programs" tab in windows.

Upvotes: 0

jonyB
jonyB

Reputation: 12015

For what it's worth, I've ran it in a virtual environment (venv) and it solved it for me

Upvotes: 0

Moh.Alkasem
Moh.Alkasem

Reputation: 59

I am using Mac and I had also same issue. I solved it by upgrading pip then install the relevant package.

Firstly install the latest version of pip:

pip3 install --upgrade pip

Then install the package (for example, numpy):

pip3 install numpy 

Upvotes: 3

Ibrahim Alvi
Ibrahim Alvi

Reputation: 21

Maybe it's not the required solution you were looking for but in my case, I had a project in pycharm that requires PIP library so I ran the following command:

pip install Pillow

in the project terminal and it got me the library required for the project. enter image description here

Upvotes: 0

Syed Muhammad Asad
Syed Muhammad Asad

Reputation: 228

Here is one line solution that works like magic

$(which python) -m pip install package_name

Upvotes: 0

Matias Huber
Matias Huber

Reputation: 11

Not sure if it is relevant, but I was having a similar issue until I realized I was trying to import request, but the module name is requests

Upvotes: 0

Steve
Steve

Reputation: 756

My Raspberry Pi 4 did not recognise the ipython command and the following was displayed when attempting to install iPython:

me@raspberrypi:~ $ sudo pip3 install ipython
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: ipython in /usr/lib/python3/dist-packages (5.8.0)
Requirement already satisfied: pexpect in /usr/lib/python3/dist-packages (from ipython) (4.6.0)

I knew this wasn't a PATH issue as iPython is a pip package.

I found an IPython directory under /usr/lib/python3/dist-packages/ and inside this directory I found program __main__.py.

Running __main__.py started iPython:

python3 /usr/lib/python3/dist-packages/IPython/__main__.py

I added the following alias to my .bashrc file to allow me to simply type ipython.

alias ipython='python3 /usr/lib/python3/dist-packages/IPython/__main__.py'

Upvotes: 0

Mudasir Habib
Mudasir Habib

Reputation: 848

Method 1

If your system has more than one Python version installed, like in my ubuntu by default Python versions are python and python3, then pip also has different versions like pip and pip3. So in this situation access pip by specific Python version with -m like:

python3 -m pip install package_name

or

python -m pip install package_name

Make sure the use of sudo if you are on Linux.

Method 2

You need to find installation directory (from where Python finds modules). For this run the following Python script:

import sys
print(sys.path)

In my case it returns:

['', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/home/mudasir_habib/.local/lib/python3.8/site-packages', '/usr/local/lib/python3.8/dist-packages', '/usr/lib/python3/dist-packages']

These are the paths that Python uses to find modules, I copy the dist-packages path. So now run the command by providing target path for installation like below:

python -m pip install package_name -t /your/copied/path

In my case I run the following command that solve my problem:

sudo python3 -m pip install keras -t /usr/lib/python3/dist-packages

Upvotes: 12

Rupesh Shingavi
Rupesh Shingavi

Reputation: 39

On my Windows machine, more than one version of Python were installed in different locations. Hence when I tried to install Pillow library as pip install Pillow, it was giving the message that "Requirement already satisfied and showing the path of another directory where another version of Python installed:

enter image description here

To solve this error, I used the --target switch with PIP command as below:

python -m pip install Pillow --target="c:\Program Files\Python310\Lib\site-packages"

And it worked successfully

Upvotes: 3

Anonymous Guy
Anonymous Guy

Reputation: 1

If you have Python 2 installed then you can use the following command to install pip for Python 2:

curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
python get-pip.py

Now you can check for pip2 and can try to run your program:

pip2 --version

Upvotes: 0

Lego Maniac
Lego Maniac

Reputation: 1

I had this problem on Windows installing pyModbusTCP. The solution for me was similar to another here. I had to run PowerShell as admin, then "pip install pyModbusTCP" worked as expected.

Upvotes: 0

Rob
Rob

Reputation: 11

Just to share my findings and perhaps a newbie error, but in my case mariadb was installed using 'sudo pip3 install mariadb' and I tried to run my script with 'python myscript.py' and that didn't work. But I worked when I use 'python3 myscript.py', seems to be that it matters which pyhton you use.

Upvotes: 1

Aymeric Bouzy aybbyk
Aymeric Bouzy aybbyk

Reputation: 2261

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

Upvotes: 30

Flavio Caduff
Flavio Caduff

Reputation: 1057

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

Upvotes: 7

cUteDeVil
cUteDeVil

Reputation: 111

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.

Upvotes: 11

Daniel Badyan
Daniel Badyan

Reputation: 149

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.

Upvotes: 12

Abhishek Parikh
Abhishek Parikh

Reputation: 989

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

Upvotes: 26

Related Questions