Expand description
Download, link, and initialize an application-local CPython interpreter.
Call initialize once during application startup, before using PyO3 or
another Python API. Python runs in isolated mode: it ignores PYTHONHOME,
PYTHONPATH, the user site directory, and application command-line arguments.
Initialization leaves the GIL released so PyO3 can attach Rust threads.
fn main() -> Result<(), pylink::Error> {
pylink::initialize()?;
// Now use pyo3::Python::attach(...), or another Python C API wrapper.
Ok(())
}Python remains initialized for the lifetime of the process. Do not call
Py_FinalizeEx or independently initialize Python while using this crate.
Prefer initializing on the main thread, which CPython treats as its main
interpreter thread.
Enums§
- Error
- An interpreter discovery or initialization error.
Constants§
- BUILD_
PYTHON_ HOME - The downloaded interpreter’s home on the build machine.
- PYO3_
CONFIG_ FILE - The generated PyO3 configuration file on the build machine.
- PYTHON_
RELEASE - The pinned Astral python-build-standalone release tag selected at build time.
- PYTHON_
VERSION - The exact CPython version selected at build time.
Functions§
- initialize
- Initialize CPython using
runtime_home. - initialize_
from - Initialize CPython with an explicit interpreter home.
- runtime_
home - Locate the Python home, or return the home already used for initialization.