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 venv
if:- You want a lightweight, simple virtual environment
- You prefer managing dependencies manually with
pip install
+requirements.txt
-
Use
pipenv
if:- 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
+venv
combo 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