pub struct Interpreter { /* private fields */ }Expand description
A Python executable and its associated platform markers.
Implementations§
Source§impl Interpreter
impl Interpreter
Sourcepub fn query(executable: impl AsRef<Path>, cache: &Cache) -> Result<Self, Error>
pub fn query(executable: impl AsRef<Path>, cache: &Cache) -> Result<Self, Error>
Detect the interpreter info for the given Python executable.
Sourcepub fn with_virtualenv(self, virtualenv: VirtualEnvironment) -> Self
pub fn with_virtualenv(self, virtualenv: VirtualEnvironment) -> Self
Return a new Interpreter with the given virtual environment root.
Sourcepub fn with_target(self, target: Target) -> Result<Self>
pub fn with_target(self, target: Target) -> Result<Self>
Return a new Interpreter to install into the given --target directory.
Sourcepub fn with_prefix(self, prefix: Prefix) -> Result<Self>
pub fn with_prefix(self, prefix: Prefix) -> Result<Self>
Return a new Interpreter to install into the given --prefix directory.
Sourcepub fn to_base_python(&self) -> Result<PathBuf, Error>
pub fn to_base_python(&self) -> Result<PathBuf, Error>
Return the base Python executable; that is, the Python executable that should be
considered the “base” for the virtual environment. This is typically the Python executable
from the Interpreter; however, if the interpreter is a virtual environment itself, then
the base Python executable is the Python executable of the interpreter’s base interpreter.
This routine relies on sys._base_executable, falling back to sys.executable if unset.
Broadly, this routine should be used when attempting to determine the “base Python
executable” in a way that is consistent with the CPython standard library, such as when
determining the home key for a virtual environment.
Sourcepub fn find_base_python(&self) -> Result<PathBuf, Error>
pub fn find_base_python(&self) -> Result<PathBuf, Error>
Determine the base Python executable; that is, the Python executable that should be
considered the “base” for the virtual environment. This is typically the Python executable
from the Interpreter; however, if the interpreter is a virtual environment itself, then
the base Python executable is the Python executable of the interpreter’s base interpreter.
This routine mimics the CPython getpath.py logic in order to make a more robust assessment
of the appropriate base Python executable. Broadly, this routine should be used when
attempting to determine the “true” base executable for a Python interpreter by resolving
symlinks until a valid Python installation is found. In particular, we tend to use this
routine for our own managed (or standalone) Python installations.
Sourcepub const fn markers(&self) -> &MarkerEnvironment
pub const fn markers(&self) -> &MarkerEnvironment
Returns the MarkerEnvironment for this Python executable.
Sourcepub fn resolver_marker_environment(&self) -> ResolverMarkerEnvironment
pub fn resolver_marker_environment(&self) -> ResolverMarkerEnvironment
Return the ResolverMarkerEnvironment for this Python executable.
Sourcepub fn key(&self) -> PythonInstallationKey
pub fn key(&self) -> PythonInstallationKey
Returns the PythonInstallationKey for this interpreter.
pub fn variant(&self) -> PythonVariant
Returns the Tags for this Python executable.
Sourcepub fn is_virtualenv(&self) -> bool
pub fn is_virtualenv(&self) -> bool
Returns true if the environment is a PEP 405-compliant virtual environment.
Sourcepub fn is_managed(&self) -> bool
pub fn is_managed(&self) -> bool
Returns true if this interpreter is managed by uv.
Returns false if we cannot determine the path of the uv managed Python interpreters.
Sourcepub fn is_externally_managed(&self) -> Option<ExternallyManaged>
pub fn is_externally_managed(&self) -> Option<ExternallyManaged>
Returns Some if the environment is externally managed, optionally including an error
message from the EXTERNALLY-MANAGED file.
See: https://packaging.python.org/en/latest/specifications/externally-managed-environments/
Sourcepub fn python_full_version(&self) -> &StringVersion
pub fn python_full_version(&self) -> &StringVersion
Returns the python_full_version marker corresponding to this Python version.
Sourcepub fn python_version(&self) -> &Version
pub fn python_version(&self) -> &Version
Returns the full Python version.
Sourcepub fn python_minor_version(&self) -> Version
pub fn python_minor_version(&self) -> Version
Returns the Python version up to the minor component.
Sourcepub fn python_patch_version(&self) -> Version
pub fn python_patch_version(&self) -> Version
Returns the Python version up to the patch component.
Sourcepub fn python_major(&self) -> u8
pub fn python_major(&self) -> u8
Return the major version component of this Python version.
Sourcepub fn python_minor(&self) -> u8
pub fn python_minor(&self) -> u8
Return the minor version component of this Python version.
Sourcepub fn python_patch(&self) -> u8
pub fn python_patch(&self) -> u8
Return the patch version component of this Python version.
Sourcepub fn python_tuple(&self) -> (u8, u8)
pub fn python_tuple(&self) -> (u8, u8)
Returns the Python version as a simple tuple, e.g., (3, 12).
Sourcepub fn implementation_major(&self) -> u8
pub fn implementation_major(&self) -> u8
Return the major version of the implementation (e.g., CPython or PyPy).
Sourcepub fn implementation_minor(&self) -> u8
pub fn implementation_minor(&self) -> u8
Return the minor version of the implementation (e.g., CPython or PyPy).
Sourcepub fn implementation_tuple(&self) -> (u8, u8)
pub fn implementation_tuple(&self) -> (u8, u8)
Returns the implementation version as a simple tuple.
Sourcepub fn implementation_name(&self) -> &str
pub fn implementation_name(&self) -> &str
Returns the implementation name (e.g., CPython or PyPy).
Sourcepub fn sys_base_exec_prefix(&self) -> &Path
pub fn sys_base_exec_prefix(&self) -> &Path
Return the sys.base_exec_prefix path for this Python interpreter.
Sourcepub fn sys_base_prefix(&self) -> &Path
pub fn sys_base_prefix(&self) -> &Path
Return the sys.base_prefix path for this Python interpreter.
Sourcepub fn sys_prefix(&self) -> &Path
pub fn sys_prefix(&self) -> &Path
Return the sys.prefix path for this Python interpreter.
Sourcepub fn sys_base_executable(&self) -> Option<&Path>
pub fn sys_base_executable(&self) -> Option<&Path>
Return the sys._base_executable path for this Python interpreter. Some platforms do not
have this attribute, so it may be None.
Sourcepub fn sys_executable(&self) -> &Path
pub fn sys_executable(&self) -> &Path
Return the sys.executable path for this Python interpreter.
Sourcepub fn real_executable(&self) -> &Path
pub fn real_executable(&self) -> &Path
Return the “real” queried executable path for this Python interpreter.
Sourcepub fn runtime_site_packages(&self) -> &[PathBuf]
pub fn runtime_site_packages(&self) -> &[PathBuf]
Return the site.getsitepackages for this Python interpreter.
These are the paths Python will search for packages in at runtime. We use this for
environment layering, but not for checking for installed packages. We could use these paths
to check for installed packages, but it introduces a lot of complexity, so instead we use a
simplified version that does not respect customized site-packages. See
Interpreter::site_packages.
Sourcepub fn stdlib(&self) -> &Path
pub fn stdlib(&self) -> &Path
Return the stdlib path for this Python interpreter, as returned by sysconfig.get_paths().
Sourcepub fn purelib(&self) -> &Path
pub fn purelib(&self) -> &Path
Return the purelib path for this Python interpreter, as returned by sysconfig.get_paths().
Sourcepub fn platlib(&self) -> &Path
pub fn platlib(&self) -> &Path
Return the platlib path for this Python interpreter, as returned by sysconfig.get_paths().
Sourcepub fn scripts(&self) -> &Path
pub fn scripts(&self) -> &Path
Return the scripts path for this Python interpreter, as returned by sysconfig.get_paths().
Sourcepub fn data(&self) -> &Path
pub fn data(&self) -> &Path
Return the data path for this Python interpreter, as returned by sysconfig.get_paths().
Sourcepub fn include(&self) -> &Path
pub fn include(&self) -> &Path
Return the include path for this Python interpreter, as returned by sysconfig.get_paths().
Sourcepub fn virtualenv(&self) -> &Scheme
pub fn virtualenv(&self) -> &Scheme
Return the Scheme for a virtual environment created by this Interpreter.
Sourcepub fn manylinux_compatible(&self) -> bool
pub fn manylinux_compatible(&self) -> bool
Return whether this interpreter is manylinux compatible.
Sourcepub fn pointer_size(&self) -> PointerSize
pub fn pointer_size(&self) -> PointerSize
Return the PointerSize of the Python interpreter (i.e., 32- vs. 64-bit).
Sourcepub fn gil_disabled(&self) -> bool
pub fn gil_disabled(&self) -> bool
Return whether this is a Python 3.13+ freethreading Python, as specified by the sysconfig var
Py_GIL_DISABLED.
freethreading Python is incompatible with earlier native modules, re-introducing
abiflags with a t flag. https://peps.python.org/pep-0703/#build-configuration-changes
Sourcepub fn debug_enabled(&self) -> bool
pub fn debug_enabled(&self) -> bool
Return whether this is a debug build of Python, as specified by the sysconfig var
Py_DEBUG.
Sourcepub fn target(&self) -> Option<&Target>
pub fn target(&self) -> Option<&Target>
Return the --target directory for this interpreter, if any.
Sourcepub fn prefix(&self) -> Option<&Prefix>
pub fn prefix(&self) -> Option<&Prefix>
Return the --prefix directory for this interpreter, if any.
Sourcepub fn is_standalone(&self) -> bool
pub fn is_standalone(&self) -> bool
Returns true if an Interpreter may be a python-build-standalone interpreter.
This method may return false positives, but it should not return false negatives. In other
words, if this method returns true, the interpreter may be from
python-build-standalone; if it returns false, the interpreter is definitely not from
python-build-standalone.
See: https://github.com/astral-sh/python-build-standalone/issues/382
Sourcepub fn layout(&self) -> Layout
pub fn layout(&self) -> Layout
Return the Layout environment used to install wheels into this interpreter.
Sourcepub fn site_packages(&self) -> impl Iterator<Item = Cow<'_, Path>>
pub fn site_packages(&self) -> impl Iterator<Item = Cow<'_, Path>>
Returns an iterator over the site-packages directories inside the environment.
In most cases, purelib and platlib will be the same, and so the iterator will contain
a single element; however, in some distributions, they may be different.
Some distributions also create symbolic links from purelib to platlib; in such cases, we
still deduplicate the entries, returning a single path.
Note this does not include all runtime site-packages directories if the interpreter has been
customized. See Interpreter::runtime_site_packages.
Sourcepub fn satisfies(&self, version: &PythonVersion) -> bool
pub fn satisfies(&self, version: &PythonVersion) -> bool
Check if the interpreter matches the given Python version.
If a patch version is present, we will require an exact match. Otherwise, just the major and minor version numbers need to match.
Sourcepub async fn lock(&self) -> Result<LockedFile, Error>
pub async fn lock(&self) -> Result<LockedFile, Error>
Grab a file lock for the environment to prevent concurrent writes across processes.
Trait Implementations§
Source§impl Clone for Interpreter
impl Clone for Interpreter
Source§fn clone(&self) -> Interpreter
fn clone(&self) -> Interpreter
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !Freeze for Interpreter
impl RefUnwindSafe for Interpreter
impl Send for Interpreter
impl Sync for Interpreter
impl Unpin for Interpreter
impl UnwindSafe for Interpreter
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more