Python Virtual Environment Setup Guides
Python Virtual Environment Setup Guides
This page explains how to create and manage Python virtual environments across Linux, Unix, macOS, and Windows. Virtual environments isolate dependencies for each project, preventing version conflicts.
📌 Navigation
Linux & Unix
Create a Virtual Environment
python3 -m venv venv
Activate
source venv/bin/activate
Install Packages
pip install requests
Deactivate
deactivate
💡 Tip: Store your environment in a .venv
folder inside your project directory for clarity.
macOS
Install Python 3 (if not already installed)
brew install python
or download from python.org
Create Environment
python3 -m venv venv
Activate
Alternative: Multiple Python Versions
Use pyenv
and pyenv-virtualenv
:
brew install pyenv pyenv-virtualenv
This allows you to manage multiple versions of Python without affecting the system installation.
Windows
Create Virtual Environment
py -m venv .venv
Activate
..venv\Scripts\activate
Install Packages
pip install requests
Deactivate
deactivate
💡 Note: Use the Python Launcher (py
) for easier version management.
Additional Notes
- The
venv
module is included in Python 3.3+. - Always add
.venv/
to.gitignore
:
.venv/
- Virtual environments prevent dependency conflicts between projects.
Summary Table
OS | Create Command | Activate Command | Deactivate Command |
---|---|---|---|
Linux/Unix | python3 -m venv .venv | source .venv/bin/activate | deactivate |
macOS | python3 -m venv .venv | source .venv/bin/activate | deactivate |
Windows | py -m venv .venv | .\\.venv\\Scripts\\activate | deactivate |