no module named 'pygame' (or any other module)
We can install external Python modules using the pip
command. To use it, we have to add it to the PATH
. PATH
is an environment variable in operating systems like Windows, macOS, and Linux that specifies directories where executable programs are located. It allows the system to find and run programs without needing their full file paths.
Instructions for the Windows operating system.
- Search for "Environment Variables" in the Start menu and click on Edit the system environment variables.
- Click on the Environment Variables button in the System Properties window.
- Under System variables, locate the
PATH
variable and select it. - Click Edit and add the path to the
python.exe
file on your computer. - Click OK to save changes and close all dialogs.
- Restart your computer to apply the changes (it isn't always necessary).
- Install the required module using
pip install moduleName
in CMD.
Warning: If you have several versions of Python on your computer, beware that if you add the
.exe
file for, e.g., Python 3.9 to the PATH
, the installed modules won't work in the Python 3.12 IDLE.