Python pip and venv: Complete Guide to Virtual Environments

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Python Dependency Management and Virtual Environments: pip, venv, virtualenv, pipenv (Updated for 2025)

Python has established itself as a powerful and flexible tool for developing projects of varying complexity. One of the language's key advantages is its vast ecosystem of libraries and tools. To manage these libraries effectively, you need to master pip and virtual environments. In this article, we'll dive deep into using pip for package installation and creating isolated virtual environments with venv, virtualenv, and pipenv — helping you streamline development and avoid dependency conflicts.

Using pip for Python Package Management

pip (Python Package Installer) is the standard package manager for Python, designed to install and manage third-party libraries available in the official PyPI (Python Package Index) repository. It lets you easily add, update, and remove packages your project needs.

Checking pip Installation

To verify that pip is installed on your system, open your terminal or command prompt and run:

pip --version

If pip is installed, you'll see its version and location. For example:

pip 24.0 from /usr/local/lib/python3.12/site-packages/pip

If pip is missing, install it by running:

python -m ensurepip --upgrade

Essential pip Commands

  • Installing a package:

    pip install package_name
    

    Example:

    pip install requests
    

    This installs the latest version of the requests package from PyPI.

  • Installing a specific version:

    pip install package_name==version_number
    

    Example:

    pip install pandas==2.2.0
    

    This installs version 2.2.0 of the pandas library.

  • Upgrading a package to the latest version:

    pip install --upgrade package_name
    

    Example:

    pip install --upgrade numpy
    

    This upgrades numpy to its newest release.

  • Uninstalling a package:

    pip uninstall package_name
    

    Example:

    pip uninstall matplotlib
    

    This removes the matplotlib package from your system.

  • Listing installed packages:

    pip list
    

    This command displays all packages installed in your current Python environment.

Installing Multiple Packages at Once

To install several packages simultaneously, use a requirements.txt file listing all needed libraries and their versions.

Create a requirements.txt file with this format:

requests==2.32.0
flask==3.0.0
pandas==2.2.0

Then run:

pip install -r requirements.txt

This installs every package listed in requirements.txt.

Saving Your Installed Packages List

To freeze your current dependencies for

Blogs

Book Recommendations