How does Python know where to import math from?


#1

Question

How does Python know where to import math from?

Answer

Python first checks to see if the module you’re trying to import matches any modules that come built in with the language. If it does, all good! If not, it searches through locations specified by sys.path, which just gives directions to where it can find modules that aren’t built in.
If you want to use modules that aren’t built in, you’ll eventually need to learn how to use pip, which installs and manages Python packages for you!


FAQ: Learn Python: Functions - Generic Imports