Skip to content
Python

Virtual Environment

Create and manage Python virtual environments.

By EZ4Code Team
venvenvironment

Code

# Command line operations
# Create virtual environment
# python -m venv venv

# Activate (Linux/Mac)
# source venv/bin/activate

# Activate (Windows)
# venv\Scripts\activate

# Deactivate
# deactivate

# Create in code
import venv
venv.create("venv", with_pip=True)

# Export dependencies
# pip freeze > requirements.txt
# Install dependencies
# pip install -r requirements.txt

Explanation

Virtual environments isolate project dependencies, avoiding version conflicts.

More Python Snippets