Python Package Management and Virtual Environment Tools Overview
This article provides a comprehensive guide to Python package management and virtual environment tools, covering pip, easy_install, virtualenv, venv, pipenv, pyenv, and autoenv, with installation commands, usage tips, and best‑practice recommendations for developers.
When programming in Python, installing and managing third‑party packages is essential; this guide introduces common tools such as pip , easy_install , and source‑based installation.
Installation methods – Recommended: use the community‑maintained pip or easy_install tools; Prohibited: system package managers like yum or apt‑get ; Specific: install from source with python setup.py install .
easy_install – Provided by setuptools , requires no extra install, but its output is unfriendly, it cannot cache packages, lacks dependency list management, and only supports installation (no uninstall or list commands). It also uses the outdated egg format.
pip advantages – Better terminal output, supports many package formats, integrates well with virtualenv , is bundled with Python 2.7.9+ and 3.4+, can manage a requirements file via the -r option, supports binary wheel packages, caches downloads, and can install packages silently with -q .
<code># Install pip tool
$ sudo apt-get install python-pip -yq
# Silent install upgrade
$ sudo pip install pip -U -q</code>Virtual environment tools
virtualenv creates isolated Python environments on a single machine, allowing multiple independent Python runtimes.
<code># Show virtualenv help
$ virtualenv --help
# Install virtualenv
$ sudo pip install virtualenv
# Create a new environment
$ virtualenv venv
# Activate the environment
$ source venv/bin/activate
# Deactivate
$ deactivate</code>venv is the standard library module introduced in Python 3.3, derived from virtualenv , used to create virtual environments without external dependencies.
<code># Create a venv (Python 3.6+)
$ python3 -m venv .env
$ source .env/bin/activate</code>pipenv combines dependency management and virtual environment creation, similar to Node.js's npm . It automatically updates pip , manages a Pipfile (in TOML format) and Pipfile.lock , and can create a .venv directory for the environment.
<code># Install pipenv for the user
$ pip install pipenv --user
# Create a project directory and initialize
$ mkdir test_pipenv && cd test_pipenv
$ pipenv install
# Activate the virtualenv
$ pipenv shell
# Install packages
$ pipenv install elasticsearch-dsl requests</code>autoenv automatically activates or deactivates virtual environments when changing directories.
<code># Install autoenv
$ sudo pip install autoenv
# Activate autoenv
$ source /usr/local/bin/activate.sh
# Create .env with activation command
$ echo "source /home/escape/venv/bin/activate" > .env</code>Version management tool – pyenv – Allows switching between multiple Python versions, but it does not replace virtual environments for dependency isolation and lacks official community endorsement.
Overall, the article recommends using pip together with virtualenv / venv or pipenv for robust package management and isolated development environments.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.