← Back to Python

All Topics

Advertisement

Learn/Python/DevOps

Environment Management

Topic: Python Environments

Advertisement

Introduction

Manage Python environments and dependencies for reproducible projects.

Virtual Environments

# Create virtual environment
python -m venv venv

# Activate
source venv/bin/activate  # Linux/Mac
venv\Scripts\activate  # Windows

# Install packages
pip install package_name

# Save dependencies
pip freeze > requirements.txt

# Install from requirements
pip install -r requirements.txt

Pipenv

# Create environment
pipenv install requests

# Activate shell
pipenv shell

# Lock and sync
pipenv lock
pipenv sync

# Remove environment
pipenv --rm

Poetry

# Create project
poetry new project_name

# Add dependencies
poetry add requests

# Install all
poetry install

# Generate lock file
poetry lock

Practice Problems

  1. Create and manage virtual environments
  2. Use requirements.txt effectively
  3. Choose between pipenv and poetry
  4. Handle multiple Python versions
  5. Share reproducible environments

Advertisement

Advertisement

Need More Practice?

Get personalized Python help from ChatWhole's AI-powered platform.

Get Expert Help →