Tutorial

Common Python Tools: Using virtualenv, Installing with Pip, and Managing Packages

Practical, beginner-friendly guide to python virtualenv and pip: install pip/virtualenv, create and activate environments, pip install/uninstall/upgrade, pip freeze and requirements.txt, and best practices.

Drake Nguyen

Founder · System Architect

3 min read
Common Python Tools: Using virtualenv, Installing with Pip, and Managing Packages
Common Python Tools: Using virtualenv, Installing with Pip, and Managing Packages

Introduction

This guide explains how to use python virtualenv and pip together to create isolated Python projects and manage dependencies. It covers core concepts, practical commands, and best practices for building reproducible environments and handling python package management across development and production.

Python on CentOS and System Python

Many Linux distributions include a system Python used by the OS. Avoid modifying that interpreter directly. Instead, install a separate Python build or use a distribution-provided alternate interpreter, then install pip and virtualenv against that custom Python to keep system tools intact.

Python, Modules and Packages

Python code is organized into modules and packages. Packages bundle modules, resources and metadata so they can be installed and reused. Manual installation via setup.py still exists, but modern workflows rely on package managers that automate installation, upgrading and dependency resolution.

Package management tools

Two historically common tools are easy_install and pip. Today, pip is the recommended tool for most workflows because it provides clearer output, dependency handling and works well with virtualenv-based workflows.

pip vs easy_install

pip vs easy_install is an important distinction for newcomers. easy_install was an early installer that offered basic install functionality. pip improves on that by downloading wheels before installation, tracking installed files, supporting uninstall, and producing reliable requirements lists. For new projects, prefer pip for installing packages from PyPI or VCS repositories.

A practical pip guide

pip is the de facto installer for Python packages. Below are common tasks and secure examples you can reuse. Run these inside a virtual environment when possible to avoid global changes.

Install pip and prerequisites

pip depends on tooling such as setuptools. On most systems you can install pip using the get-pip.py bootstrap script (or the system package manager). After installation, ensure the bin directory (for example /usr/local/bin) is on your PATH.

curl -sS https://bootstrap.pypa.io/get-pip.py | python3

Installing packages with pip

Common pip install patterns:

  • Install latest from PyPI: pip install requests
  • Install a specific version: pip install Django==3.2.18
  • Install from a git repository: pip install git+https://github.com/owner/repo.git@branch

Uninstalling and upgrading

  • Uninstall: pip uninstall package_name
  • Upgrade: pip install --upgrade package_name

Listing and freezing

To inspect installed packages use pip list. To create a reproducible requirements file use pip freeze, which outputs pins suitable for later installation.

pip freeze > requirements.txt

Compare pip freeze vs pip list: pip list shows installed packages and versions, while pip freeze produces a requirements-style output intended for exact reproduction.

Installing from a requirements file

Install all dependencies recorded in a requirements file inside a virtualenv:

pip install -r requirements.txt

Searching for packages

The older pip search command is deprecated in many pip releases. Use the PyPI website or pip index commands (if available) to discover packages.

virtualenv: isolated Python environments

A python virtual environment is a directory that contains a specific Python interpreter and its own site-packages. Using virtualenv isolates project dependencies so different projects Netalith not conflict and you can install python packages without sudo.

Why use virtualenv?

  • Create isolated environments per project
  • Install packages without admin privileges
  • Pin and reproduce project dependencies using a requirements file
  • Package and deploy applications consistently

Install virtualenv

Install virtualenv globally (or install it inside a user install):

pip install --user virtualenv

Or install using sudo if you need a system-wide binary:

sudo pip install virtualenv

Create a virtual environment with a specific interpreter

To create an environment using a specific Python interpreter (for example python3):

virtualenv --python=/usr/bin/python3 venv

Activate and deactivate a virtualenv

Activate the environment to put its python and pip on your PATH. When finished, deactivate to return to the system interpreter.

source venv/bin/activate
# work with python and pip inside the env
deactivate

Use virtualenv without activation

You can also run the environment's interpreter and pip directly without activating it:

venv/bin/python script.py
venv/bin/pip install -r requirements.txt

Typical workflow: create, install, freeze

Example sequence for a new project:

virtualenv -p python3 venv
source venv/bin/activate
pip install -r requirements.txt
pip freeze > requirements.txt

This workflow makes it easy to share dependencies with teammates and deployers.

Best practices and tips

  • Always use virtualenv or venv for project work to avoid polluting system Python.
  • Pin exact versions in requirements.txt for production deployments (pip freeze output).
  • Prefer pip over easy_install and use wheels when available for faster installs.
  • When installing system-wide tools, consider user installs (pip install --user) or create a dedicated system Python to avoid sudo where possible.

Using python virtualenv and pip together gives you reliable environment isolation and repeatable dependency management—essential for modern Python development.

Stay updated with Netalith

Get coding resources, product updates, and special offers directly in your inbox.