Install & Compatibility
Where this runs
tested against v0.1.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
pyroapi
✓ import pyroapi
✗ import pyro.generic
The pyro.generic module was moved to the standalone pyroapi package in version 0.1.0.
set_backend
✓ from pyroapi import set_backend
distributions
✓ import pyroapi.distributions as dist
param
✓ import pyroapi.params as params
handlers
✓ import pyroapi.handlers as handlers
This quickstart demonstrates how to set a backend for `pyro-api` and access its generic modules for distributions and parameters. Remember, `pyro-api` is an interface; you must install a concrete backend like `pyro` or `numpyro` for it to function correctly. The `set_backend()` call typically needs to happen early in your application's lifecycle.
import pyroapi
import os
# IMPORTANT: pyro-api is an interface. You must install a backend.
# For example, run: pip install pyro
# Or for NumPyro: pip install numpyro
# Set the backend. This line typically goes near the start of your script.
# 'pyro' is a common default, but 'numpyro' or 'funsor' are also options.
# If the chosen backend is not installed, set_backend will raise an error.
try:
backend_name = os.environ.get('PYRO_BACKEND', 'pyro') # Use env var for testing
pyroapi.set_backend(backend_name)
print(f"Pyro-API backend successfully set to: {pyroapi.get_backend()}")
# Now you can use the generic API for distributions, parameters, etc.
import pyroapi.distributions as dist
import pyroapi.params as params
# Example: Define a generic parameter and a distribution
mean_param = params.param("mean_value", 0.0)
std_param = params.param("std_value", 1.0, constraint=dist.constraints.positive)
generic_normal = dist.Normal(mean_param, std_param)
print(f"\nCreated a generic Normal distribution with mean {mean_param.data} and std {std_param.data}")
except ImportError as e:
print(f"Failed to set Pyro-API backend: {e}")
print("Please ensure your chosen backend (e.g., 'pyro' or 'numpyro') is installed.")
except Exception as e:
print(f"An unexpected error occurred: {e}")
Errors
Common errors & fixes
RuntimeError: No backend is currently set for pyro-api. Please call pyro_api.set_backend() before using pyro-api.
The pyro-api library is a backend-agnostic interface and requires an explicit backend (e.g., 'pyro', 'numpyro') to be set before any probabilistic programming operations can be performed.
fiximport pyro_api
pyro_api.set_backend('pyro') # or 'numpyro', 'funsor' ModuleNotFoundError: No module named 'pyro-api'
Python module names use underscores instead of hyphens; while the package is installed as `pyro-api`, it is imported as `pyro_api`.
AttributeError: module 'pyro_api' has no attribute 'Normal'
Distributions like `Normal` are located within the `pyro_api.distributions` submodule, not directly under the top-level `pyro_api` module.
fixfrom pyro_api import distributions
x = distributions.Normal(0., 1.)
ValueError: Unknown backend 'foo'. Available backends are: ['pyro', 'numpyro', 'funsor']
The specified backend name in `pyro_api.set_backend()` is not a recognized or supported backend for the pyro-api library.
fiximport pyro_api
pyro_api.set_backend('numpyro') # Use a valid backend name like 'pyro' or 'numpyro' Upgrade
Version history
0.1.2latest on PyPI · released May 15, 2020
Audit
Dependencies
No dependency data recorded yet.