Skip to main content

Python Tutorial 6.4 - Environment Management in Python

Welcome to the “Environment Management” tutorial!


Overview

Isolate project dependencies using virtual environments and tools.

Built-in venv

  1. Create env:
    python -m venv venv
    
  2. Activate:
    • Windows: venv\Scripts\activate
    • macOS/Linux: source venv/bin/activate
  3. Install packages:
    pip install requests
    
  4. Freeze requirements:
    pip freeze > requirements.txt
    

pipenv (Alternate)

pip install pipenv
pipenv install requests
pipenv shell

poetry (Alternate)

pip install poetry
poetry init
poetry add requests
poetry shell

Key Takeaways

  • Use virtual environments to keep projects isolated.
  • Tools like pipenv and poetry simplify dependency management.

Happy coding!

Comments