Introduction to Python's Modules
CSCI 1470
by K. Yue
1. Introduction to Python's Modules
- A module is a file containing Python definitions and statements.
- The file name is the module name with the suffix .py appended as the file extension. Examples: sys.py, turtle.py, wikipedia.py
- Documentation: https://docs.python.org/3/tutorial/modules.html.
- There are many advantages of using Python modules:
- Code reusability: uses Python code developed and tested by experienced Python developers.
- Code organization: allows local grouping of related code into files.
- Other advantages...
- The Python program being executed is known as the main module.
- A module can use other modules by importing them.
- "Within a module, the module’s name (as a string) is available as the value of the global variable __name__."

- A Python package is a way to organize related modules into a directory hierarchy.
1.1 Built-in Python modules
- Built-in Python modules are pre-installed Python modules that come with the Python installation.
- It can be regarded as Python's standard library.
- Users do not need to install built-in Python modules themselves. They are already there.
- To manage and access Python modules effectively, they are stored in specific folders (usually the Lib sub-directory of the Python installation.
- Example:

2. External Python modules and Python
- External Python modules are modules not come with Python standard library.
- They are also known as third party modules.
- Packages containing these external Python modules need to be downloaded and properly installed before using.
- pip (Pip Installs Packages) is the python program for installing and managing Python packages.

- Use "pip install <<module_to_be_install>>" in a command prompt to install a package.
- The Python Package Index (PyPI) is the official repository for Python software packages.
- When using "pip install wikipedia" (for example), pip will check PyPI for the package wikipedia, and then download, unpack and install the package.
Examples:
pip3.13 install numpy
pip3.12 install numpy
pip3 install scipy
pip install wikipedia
- Other common pip commands:
- pip3.13 help
- pip3.13 list
- pip3.13 uninstall