Environment
Virtual Environments
Section titled “Virtual Environments”Virtual environments (venv) isolate your project’s dependencies from the system Python so different projects don’t conflict.
Create and activate a venv:
# Create a venv in the .venv folder (convention)python -m venv .venv
# On Windows Command Prompt.venv\Scripts\Activate.bat
# On Windows PowerShell.venv\Scripts\Activate.ps1
# Activate (macOS/Linux)source .venv/bin/activate
# Verifypython -VDeactivate with deactivate.
# Activate (macOS/Linux)source .venv/bin/deactivate
# On Windows PowerShell# .venv\Scripts\Deactivate.ps1Installing Packages (pip)
Section titled “Installing Packages (pip)”Install, upgrade, uninstall:
pip install numpypip install --upgrade pippip uninstall numpyFreeze your current environment to a requirements file:
pip freeze > requirements.txtInstall from a requirements.txt:
pip install -r requirements.txtRunning Modules
Section titled “Running Modules”Use the -m flag to run installed modules and ensure the correct interpreter is used:
python -m http.server 8000Common Workflows
Section titled “Common Workflows”# 1) Create project and venvmkdir myapp && cd myapppython -m venv .venvsource .venv/bin/activate
# 2) Install depspip install numpy
# 3) Save exact versionspip freeze > requirements.txt
# 4) Recreate env latervenv .venvsource .venv/bin/activatepip install -r requirements.txtJupyter Notebook + VS Code
Section titled “Jupyter Notebook + VS Code”Extensions
Section titled “Extensions”- https://marketplace.visualstudio.com/items?itemName=ms-python.python
- https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter
Optional Extensions
Section titled “Optional Extensions”JupyterLab
Section titled “JupyterLab”JupyterLab is the next-generation web interface for Jupyter notebooks, consoles, and file management.
Install
Section titled “Install”pip install jupyterlab# Start JupyterLab (opens in your browser)jupyter lab- If the browser does not open, copy the token URL printed in the terminal to your browser.
- Stop the server with
Ctrl+Cin the terminal.
Google Colab
Section titled “Google Colab”Free, cloud-based platform that allows users to write and execute Python code in a Jupyter Notebook environment.