Unable to import libraries in python even though i have the libraries installed


I can’t import libraries in python that I have installed using pip
as shown here.

Even other libraries such as PySimpleGui and PyGame don’t work when I try to import them.

I have tried uninstalling and reinstalling the libraries and I am sure they are installed on my computer.

Asked By: Manan Shah



I think you might have installed them under a different folder or space than what you need. For example the code below installs the library at your current space, while simply pip3 install pygame might be somewhere else.

python3 -m pip3 install pygame
Answered By: ThatOneAmazingPanda

To sort this out, you need to establish two things:

  • where you (i.e. pip) installed the packages, and
  • where Python is looking for them

You can find where pip installed a package with:

pip show PACKAGE # e.g. pip show flask

Obviously, if you install using pip3 install flask, you will need to use:

pip3 show flask

Now you need to see which Python you are running and where it is looking for its packages:

import sys

print(sys.executable) # show which Python we are running
print(sys.path)       # show where it is looking for packages

Hopefully you will see you are not installing into the Python interpreter you are using.

Answered By: Mark Setchell

I seem to have fixed the problem, i was using a different interpreter as to which my packages were installed in as pointed out by Mohammad Jafari.

Thanks for all your help

Answered By: Manan Shah
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.