What is a module?
Python is a programming language. A module is a ready-made set of code you can borrow, like a tool from a toolbox. Instead of writing everything yourself, you write import name and use the tool. Packages are bigger collections of modules.
Different Python versions and different virtual environments have different modules. A virtual environment is a private folder that keeps one app's tools apart from other apps.
Method 1: Ask pip
pip is the tool that installs and lists Python packages.
- Open a terminal. On hosting, connect with SSH if it is enabled on your plan.
- If your app uses a virtual environment, enter it first. In cPanel, the Setup Python App page shows the exact command to copy.
- Run:
python -m pip list
This prints each installed package with its version. On some systems you must type python3 instead of python.
Method 2: Ask Python itself
- Start Python:
python3
- Type:
help("modules")
This prints a long list of every module Python can find, including built-in ones. It may take a moment.
- Type
exit()to leave.
Method 3: Test one module
If you only need to know whether one module exists, try to import it:
python3 -c "import requests; print(requests.__version__)"
If the module exists, you see its version. If not, you see "ModuleNotFoundError".
Method 4: Save the list
python -m pip freeze > requirements.txt
This writes the list into a file named requirements.txt. You can use it later to install the same set on another server.
If a module is missing
- Enter the right virtual environment.
- Run
python -m pip install module-name. - Restart your app so it can use the new module.
Quick recap
- A module is ready-made code you can reuse.
- Use
python -m pip listto see installed packages. - Use
help("modules")for the full list. - Work inside the right virtual environment.