How does python find a module file if the import statement only contains the filename?
Question: Everywhere I see Python code importing modules using `import sys` or `import
mymodule`

How does the interpreter find the correct file if no directory or path is
provided?


Answer: <http://docs.python.org/2/tutorial/modules.html#the-module-search-path>

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

For information on the "installation-specific default", see documentation on
[the `site` module](https://docs.python.org/3/library/site.html#module-site).

