however there is no folder called math in the project folder and no modules named exp, sqrt, and ceil. My question is basically where are these modules being imported from and how do I see them and other files like them? Thanks in advance.

5 Answers
5

You have some confused terminology. In this case, math is the module, and exp, sqrt, ceil are functions it defines. Usually it is from <module> import <function/class>. math is a base module which is included with every Python installation. Python has set of specific places it will look for the module. In this case, math will be a dynamically loaded module written in C.

You can find out where it comes from by doing:

import math
math.__file__

Note that this will give an error for anything that is inbuilt into the interpreter, however.

You are seeing the Python standard libraries. They are resolved by searching the PYTHONPATH for matching modules. In addition to the PYTHONPATH, you can import from any subfolders of your python script that contain a file called __init__.py

When a module named spam is imported, the interpreter first searches for a built-in module with that name. If not found, it then searches for a file named spam.py in a list of directories given by the variable sys.path. sys.path is initialized from these locations:

- The directory containing the input script (or the current directory).
- PYTHONPATH (a list of directory names, with the same syntax as the shell variable PATH).
- the installation-dependent default.

After initialization, Python programs can modify sys.path. The directory containing the script being run is placed at the beginning of the search path, ahead of the standard library path. This means that scripts in that directory will be loaded instead of modules of the same name in the library directory. This is an error unless the replacement is intended. See section Standard Modules for more information.