DEV Community

Muhammad Atif Iqbal
Muhammad Atif Iqbal

Posted on

Difference between `pipenv` and `python -m venv` Environments

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
Enter fullscreen mode Exit fullscreen mode

Using pipenv:

pipenv install fastapi
pipenv shell
# Pipfile and Pipfile.lock are auto-managed
Enter fullscreen mode Exit fullscreen mode

Top comments (0)