Difference between pipenv and python -m venv Environments in Python
Both pipenv and python -m venv are tools used to create isolated Python environments, but they serve slightly different purposes and have different features.
Here's a side-by-side comparison:
π Pipenv vs python -m venv
| Feature | pipenv |
python -m venv |
|---|---|---|
| π§ Purpose | Virtualenv + Dependency Management Tool | Just creates a virtual environment |
π¦ Handles requirements.txt
|
Uses Pipfile and Pipfile.lock instead |
You manage requirements.txt manually |
| π Dependency resolution | Automatically resolves compatible versions | You install packages manually |
| π§ͺ Automatically installs pip | β Yes | β Yes |
| π Easy to see dependencies | pipenv graph |
No built-in dependency graph viewer |
π Creates .venv folder |
β Yes | β
Yes (default is .venv or env) |
| β‘ Run scripts inside env | pipenv run your_script.py |
.\venv\Scripts\python your_script.py |
| π¬ Enter shell | pipenv shell |
.\venv\Scripts\activate (Windows) |
| π Lockfile support | β
(Pipfile.lock) |
β You must create requirements.txt
|
| π Version pinning | β Built-in | Manual (you pin versions in requirements.txt) |
π‘ Summary
-
Use
python -m venvif:- You want a lightweight, simple virtual environment
- You prefer managing dependencies manually with
pip install+requirements.txt
-
Use
pipenvif:- You want an all-in-one tool for managing dependencies and virtual environments
- You like automatic lockfile creation and version resolution
- You want a
pip install+venvcombo with nicer CLI commands
π§ Real-World Example
Using python -m venv:
python -m venv venv
.\venv\Scripts\activate
pip install fastapi
pip freeze > requirements.txt
Using pipenv:
pipenv install fastapi
pipenv shell
# Pipfile and Pipfile.lock are auto-managed
Top comments (0)