简体   繁体   中英

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.

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

  • where you (ie 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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM