Search code examples
pythonpip

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.


Solution

  • 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.