How to beginner · 3 min read

How to install Weights and Biases

Quick answer
Install Weights and Biases by running pip install wandb in your Python environment. Then, initialize it in your code with import wandb and wandb.init() to start tracking experiments.

PREREQUISITES

  • Python 3.8+
  • pip package manager
  • Internet connection for package download

Setup

Install the Weights and Biases Python SDK using pip. This package enables experiment tracking, logging, and visualization for machine learning projects.

Set your API key via environment variable WANDB_API_KEY or login interactively after installation.

bash
pip install wandb

Step by step

Here is a minimal example to install and initialize Weights and Biases in a Python script to track a simple metric.

python
import wandb

# Initialize a new run
wandb.init(project="my-project")

# Log a metric
for epoch in range(3):
    wandb.log({"epoch": epoch, "accuracy": 0.8 + epoch * 0.05})

print("Run completed and logged to W&B.")
output
Run completed and logged to W&B.

Common variations

  • Use wandb.login() to authenticate interactively if you don't want to set the API key as an environment variable.
  • Integrate with popular ML frameworks like PyTorch or TensorFlow by adding wandb.watch(model) to log gradients and parameters.
  • Run asynchronously or in distributed training setups by configuring wandb.init() with appropriate parameters.

Troubleshooting

  • If you see wandb: ERROR API key not found, set your API key with export WANDB_API_KEY=your_api_key on Linux/macOS or setx WANDB_API_KEY your_api_key on Windows.
  • For network issues, ensure your firewall allows outbound HTTPS traffic to api.wandb.ai.
  • If pip install wandb fails, upgrade pip with pip install --upgrade pip and retry.

Key Takeaways

  • Use pip install wandb to install the Weights and Biases SDK quickly.
  • Set your API key via the WANDB_API_KEY environment variable for seamless authentication.
  • Initialize tracking in your Python code with wandb.init() and log metrics with wandb.log().
  • Use wandb.login() for interactive authentication if preferred over environment variables.
  • Troubleshoot common errors by verifying API key setup and network connectivity.
Verified 2026-04
Verify ↗