Pip is a package manager that installs third-party packages (such as PyAutoGUI, Matplotlib, or Pygame) from https://pypi.org/, the Python Package Index. For a more detailed blog post on how pip works, see What Is Pip? A Guide for New Pythonistas
On Windows, to install a module named module_name open a Command Prompt window and run:
pip install --user module_name
On macOS and Linux,
pip is for the older Python 2 version, so you need to open a Terminal window and run
pip3 install --user module_name
(If you get a
'pip' is not recognized as an internal or external command, operable program or batch file. or
pip3: command not found error message, then the folder that the pip tool is listed in must be added to the PATH environment variable. You can find out about hte command line and environment variables in Chapter 2: Environment Setup and the Command Line in my free book, Beyond the Basic Stuff with Python.
If you can run
python3 from the terminal/command prompt window without errors, you can use Python itself to run pip by entering the following on Windows:
python -m pip install --user module_name
On macOS and Linux, run:
python3 -m pip install --user module_name
Remember to run
python from the command line (either Terminal or Command Prompt) and not from the Python interactive shell. The Python interactive shell will have the
>>> prompt. However, you can run pip from the Python interactive shell by running the following Python code:
import sys, os; os.system(sys.executable + ' -m pip install --user module_name')
Note the space before the
-m is required. Replace module_name with the name of the module you wish to install, but type everything else exactly as shown.
You can find packages to install by browsing PyPI, the Python Package Index, at https://pypi.org/
Learn to program with my books for beginners, free under a Creative Commons license:
Take my Automate the Boring Stuff with Python online Udemy course. Use this link to apply a 60% discount.