Weights & Biases (wandb)
raw JSON → 0.25.1 verified Tue May 12 auth: no python install: verified
Weights & Biases (wandb) is a MLOps platform for experiment tracking, model optimization, and collaboration, widely used by machine learning practitioners. It provides a CLI and Python library to log metrics, visualize results, and manage models from experimentation to production. The library is actively maintained with frequent releases, typically on a monthly or bi-monthly cadence, and is currently at version 0.25.1.
pip install wandb Common errors
error ModuleNotFoundError: No module named 'wandb' ↓
cause The `wandb` library is not installed in the current Python environment.
fix
pip install wandb
error wandb: ERROR W&B API key is not set. Please set the WANDB_API_KEY environment variable or run `wandb login` ↓
cause The Weights & Biases API key is not configured, which is required to authenticate and log runs to the W&B server.
fix
Run
wandb login in your terminal and follow the prompts, or set the WANDB_API_KEY environment variable. error ValueError: This experiment has already been initialized. ↓
cause `wandb.init()` was called multiple times within the same process without properly finishing the previous run.
fix
Ensure
wandb.init() is called only once per experiment run, or explicitly call wandb.finish() before subsequent wandb.init() calls. error TypeError: Object of type int64 is not JSON serializable ↓
cause Attempting to log a NumPy `int64` type directly with `wandb.log()`, which is not natively JSON serializable.
fix
Convert the
int64 value to a standard Python integer (int) before logging, e.g., int(numpy_int64_value). error wandb: WARNING wandb.finish() was called but there is no active run. ↓
cause `wandb.finish()` was called when no active Weights & Biases run was initialized or if the run had already finished.
fix
Ensure
wandb.finish() is called only once at the end of an active wandb.init() run, or guard it with if wandb.run: wandb.finish(). Warnings
breaking Python 3.8 is no longer supported starting from `wandb` version 0.25.0. ↓
fix Upgrade your Python environment to 3.9 or higher.
breaking The legacy `wandb.beta.workflows` module (including `log_model()`, `use_model()`, `link_model()`) was removed in version 0.24.0. These functions are no longer available and will cause `AttributeError`. ↓
fix Migrate to the modern artifact API using `Run.log_artifact()`, `Run.use_artifact()`, and `Run.link_artifact()` methods.
breaking Version `0.24.0` was yanked from PyPI due to a critical bug that could cause silent failure to upload some run data. If used, data might be missing from your W&B dashboard. ↓
fix Immediately upgrade to `wandb` version `0.24.1` or higher. Missing data from `0.24.0` runs can often be recovered by running `wandb sync` on the `.wandb` files.
deprecated Several `wandb.Run` methods are deprecated in favor of direct properties, including `run.project_name()`, `run.get_url()`, `run.get_project_url()`, and `run.get_sweep_url()`. ↓
fix Use the direct properties instead: `run.project`, `run.url`, `run.project_url`, and `run.sweep_url` respectively.
gotcha The `wandb: ERROR Run aborted` or `wandb: ERROR Failed to log data` messages indicate an unexpected termination or data logging failure. This can be caused by script errors, system resource constraints, or network connectivity issues. ↓
fix Check script for exceptions, monitor system resources (CPU/RAM), verify stable network connection, and ensure data logged to `wandb.log()` is in the correct dictionary format.
gotcha Programmatic dataset splitting (e.g., using `sklearn.model_selection.train_test_split` without fixing `random_state` or without managing splits as artifacts) can lead to inconsistent train/test sets when new data is added, invalidating comparisons between experiments. ↓
fix Ensure reproducibility of splits (e.g., set `random_state` or explicitly manage dataset versions as W&B Artifacts) to maintain consistent evaluation benchmarks across experiments.
gotcha The `wandb.errors.errors.UsageError: No API key configured` indicates that the W&B API key has not been set up, preventing authentication. This is a common first-time setup error when calling `wandb.login()` or any method that requires authentication. ↓
fix Ensure you have logged in using `wandb login` in your terminal or script, or by setting the `WANDB_API_KEY` environment variable with your API key (available from your W&B settings page).
gotcha The `wandb.login()` function raises `wandb.errors.errors.UsageError: No API key configured` if it cannot find an API key, preventing any W&B operations. ↓
fix Ensure you have logged in via the command line (`wandb login`), set the `WANDB_API_KEY` environment variable, or passed the API key directly to `wandb.login(key='YOUR_API_KEY')`.
Install compatibility verified last tested: 2026-05-12
python os / libc status wheel install import disk
3.10 alpine (musl) wheel - 4.20s 133.2M
3.10 alpine (musl) - - 3.45s 134.2M
3.10 slim (glibc) wheel 7.6s 2.50s 135M
3.10 slim (glibc) - - 1.96s 135M
3.11 alpine (musl) wheel - 4.89s 140.9M
3.11 alpine (musl) - - 4.70s 141.8M
3.11 slim (glibc) wheel 6.7s 3.63s 142M
3.11 slim (glibc) - - 2.86s 143M
3.12 alpine (musl) wheel - 4.38s 131.5M
3.12 alpine (musl) - - 4.12s 132.4M
3.12 slim (glibc) wheel 5.9s 3.53s 133M
3.12 slim (glibc) - - 3.38s 134M
3.13 alpine (musl) wheel - 3.69s 131.3M
3.13 alpine (musl) - - 3.39s 132.2M
3.13 slim (glibc) wheel 6.3s 2.89s 133M
3.13 slim (glibc) - - 2.70s 133M
3.9 alpine (musl) wheel - 4.05s 132.3M
3.9 alpine (musl) - - 3.36s 133.4M
3.9 slim (glibc) wheel 8.7s 3.19s 134M
3.9 slim (glibc) - - 2.28s 134M
Imports
- wandb
import wandb - wandb.init
import wandb wandb.init(...) - wandb.login
import wandb wandb.login()
Quickstart last tested: 2026-04-24
import wandb
import os
# Authenticate with W&B. For automated environments, use an environment variable.
# wandb.login() will prompt for an API key if not set.
# Set WANDB_API_KEY environment variable for CI/CD or headless environments.
# For local development, running `wandb login` in your terminal is common.
# os.environ.get('WANDB_API_KEY', '') # Example for fetching from env, but wandb.login() handles this.
wandb.login()
# Initialize a new W&B run
project_name = os.environ.get('WANDB_PROJECT', 'my-awesome-project')
config = {
'epochs': 10,
'lr': 0.01,
'batch_size': 32
}
with wandb.init(project=project_name, config=config) as run:
# Access hyperparameters
epochs = run.config.epochs
learning_rate = run.config.lr
print(f"Starting training for {epochs} epochs with LR: {learning_rate}")
# Simulate a training loop
for epoch in range(epochs):
# Simulate loss and accuracy metrics
loss = 1.0 / (epoch + 1) + 0.1 * (epochs - epoch - 1) / epochs
accuracy = 0.5 + 0.5 * (epoch + 1) / epochs
# Log metrics to W&B
run.log({"epoch": epoch, "loss": loss, "accuracy": accuracy})
print(f"Epoch {epoch+1}/{epochs}: Loss = {loss:.4f}, Accuracy = {accuracy:.4f}")
print("Training complete!")