Course contentsShow
← Python
Lesson 5 of 1,0601. Foundations and EnvironmentFree lesson

Installing Packages Using the Pip Package Manager

You will use the pip tool to install, update, and remove third-party libraries from the Python Package Index to extend your project functionality.

In this lesson, you will learn how to use pip to download and manage external code libraries from the Python Package Index (PyPI) to expand your project's capabilities.

What is Pip?

Think of Python as a car you’ve just bought. Out of the box, it’s great for getting around, but you might eventually want a roof rack, a better sound system, or off-road tires. In Python, these extra features are called packages (or libraries). pip is the built-in tool that acts as your online "auto parts store," allowing you to search, download, and attach these tools to your project.

Managing Packages

Before running these commands, ensure you have activated your virtual environment, as this keeps your project clean and isolated.

1. Installing a package To add a new library—for example, requests, which is popular for fetching data from the web—run this in your terminal:

pip install requests

pip will connect to the internet, find the latest version of the library, and install it into your active environment.

2. Updating a package Libraries receive updates to fix bugs or add features. If you want to make sure your library is up-to-date, use:

pip install --upgrade requests

3. Removing a package If you no longer need a library and want to save space or clean up your environment, use the uninstall command:

pip uninstall requests

Why does this matter?

The Python ecosystem is massive because thousands of developers contribute their code to PyPI. By mastering pip, you aren't just writing your own code from scratch; you are standing on the shoulders of giants by leveraging professional-grade tools for tasks like data analysis, web development, or automation.

Because you have already learned how to set up virtual environments in the previous lesson, remember: always install your packages after activating your environment. This ensures your project only uses the specific versions of the libraries it needs, preventing "dependency hell" where different projects accidentally overwrite each other's files.

Key Takeaway: Use pip install <package_name> to download libraries into your virtual environment, keeping your project organized and fully featured.