pub struct InterpreterConfig {
    pub implementation: PythonImplementation,
    pub version: PythonVersion,
    pub shared: bool,
    pub abi3: bool,
    pub lib_name: Option<String>,
    pub lib_dir: Option<String>,
    pub executable: Option<String>,
    pub pointer_width: Option<u32>,
    pub build_flags: BuildFlags,
    pub suppress_build_script_link_lines: bool,
    pub extra_build_script_lines: Vec<String>,
}
Expand description

Configuration needed by PyO3 to build for the correct Python implementation.

Usually this is queried directly from the Python interpreter, or overridden using the PYO3_CONFIG_FILE environment variable.

When the PYO3_NO_PYTHON variable is set, or during cross compile situations, then alternative strategies are used to populate this type.

Fields§

§implementation: PythonImplementation

The Python implementation flavor.

Serialized to implementation.

§version: PythonVersion

Python X.Y version. e.g. 3.9.

Serialized to version.

§shared: bool

Whether link library is shared.

Serialized to shared.

§abi3: bool

Whether linking against the stable/limited Python 3 API.

Serialized to abi3.

§lib_name: Option<String>

The name of the link library defining Python.

This effectively controls the cargo:rustc-link-lib=<name> value to control how libpython is linked. Values should not contain the lib prefix.

Serialized to lib_name.

§lib_dir: Option<String>

The directory containing the Python library to link against.

The effectively controls the cargo:rustc-link-search=native=<path> value to add an additional library search path for the linker.

Serialized to lib_dir.

§executable: Option<String>

Path of host python executable.

This is a valid executable capable of running on the host/building machine. For configurations derived by invoking a Python interpreter, it was the executable invoked.

Serialized to executable.

§pointer_width: Option<u32>

Width in bits of pointers on the target machine.

Serialized to pointer_width.

§build_flags: BuildFlags

Additional relevant Python build flags / configuration settings.

Serialized to build_flags.

§suppress_build_script_link_lines: bool

Whether to suppress emitting of cargo:rustc-link-* lines from the build script.

Typically, pyo3’s build script will emit cargo:rustc-link-lib= and cargo:rustc-link-search= lines derived from other fields in this struct. In advanced building configurations, the default logic to derive these lines may not be sufficient. This field can be set to Some(true) to suppress the emission of these lines.

If suppression is enabled, extra_build_script_lines should contain equivalent functionality or else a build failure is likely.

§extra_build_script_lines: Vec<String>

Additional lines to println!() from Cargo build scripts.

This field can be populated to enable the pyo3 crate to emit additional lines from its its Cargo build script.

This crate doesn’t populate this field itself. Rather, it is intended to be used with externally provided config files to give them significant control over how the crate is build/configured.

Serialized to multiple extra_build_script_line values.

Implementations§

source§

impl InterpreterConfig

source

pub fn from_sysconfigdata(sysconfigdata: &Sysconfigdata) -> Result<Self>

Generate from parsed sysconfigdata file

Use parse_sysconfigdata to generate a hash map of configuration values which may be used to build an InterpreterConfig.

source

pub fn generate_import_libs(&mut self) -> Result<()>

source

pub fn run_python_script(&self, script: &str) -> Result<String>

Run a python script using the InterpreterConfig::executable.

Panics

This function will panic if the executable is None.

source

pub fn run_python_script_with_envs<I, K, V>( &self, script: &str, envs: I ) -> Result<String>where I: IntoIterator<Item = (K, V)>, K: AsRef<OsStr>, V: AsRef<OsStr>,

Run a python script using the InterpreterConfig::executable with additional environment variables (e.g. PYTHONPATH) set.

Panics

This function will panic if the executable is None.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.