pythonfinder package

class pythonfinder.Finder(path=None, system=False, global_search=True, ignore_unsupported=True, sort_by_path=False)[source]

Bases: object

A cross-platform Finder for locating python and other executables.

Searches for python and other specified binaries starting in path, if supplied, but searching the bin path of sys.executable if system is True, and then searching in the os.environ['PATH'] if global_search is True. When global_search is False, this search operation is restricted to the allowed locations of path and system.

create_system_path()[source]
find_all_python_versions(major=None, minor=None, patch=None, pre=None, dev=None, arch=None, name=None)[source]
find_python_version(major=None, minor=None, patch=None, pre=None, dev=None, arch=None, name=None, sort_by_path=False)[source]

Find the python version which corresponds most closely to the version requested.

Parameters
  • int] major (Union[str,) – The major version to look for, or the full version, or the name of the target version.

  • minor (Optional[int]) – The minor version. If provided, disables string-based lookups from the major version field.

  • patch (Optional[int]) – The patch version.

  • pre (Optional[bool]) – If provided, specifies whether to search pre-releases.

  • dev (Optional[bool]) – If provided, whether to search dev-releases.

  • arch (Optional[str]) – If provided, which architecture to search.

  • name (Optional[str]) – Name of the target python, e.g. anaconda3-5.3.0

  • sort_by_path (bool) – Whether to sort by path – default sort is by version(default: False)

Returns

A new PathEntry pointer at a matching python version, if one can be located.

Return type

pythonfinder.models.path.PathEntry

classmethod parse_major(major, minor=None, patch=None, pre=None, dev=None, arch=None)[source]
rehash()[source]
reload_system_path()[source]

Rebuilds the base system path and all of the contained finders within it.

This will re-apply any changes to the environment or any version changes on the system.

property system_path
which(exe)[source]
property windows_finder
exception pythonfinder.InvalidPythonVersion[source]

Bases: Exception

Raised when parsing an invalid python version

class pythonfinder.SystemPath(global_search=True, paths=NOTHING, executables=NOTHING, python_executables=NOTHING, path_order=NOTHING, python_version_dict=NOTHING, only_python=False, pyenv_finder=None, asdf_finder=None, windows_finder=None, system=False, version_dict=NOTHING, ignore_unsupported=False, SystemPath__finders=NOTHING)[source]

Bases: object

static check_for_asdf()[source]
static check_for_pyenv()[source]
clear_caches()[source]
classmethod create(path=None, system=False, only_python=False, global_search=True, ignore_unsupported=True)[source]

Create a new pythonfinder.models.SystemPath instance.

Parameters
  • path – Search path to prepend when searching, defaults to None

  • path – str, optional

  • system (bool) – Whether to use the running python by default instead of searching, defaults to False

  • only_python (bool) – Whether to search only for python executables, defaults to False

  • ignore_unsupported (bool) – Whether to ignore unsupported python versions, if False, an error is raised, defaults to True

Returns

A new pythonfinder.models.SystemPath instance.

Return type

pythonfinder.models.SystemPath

create_python_version_dict()[source]
executables
find_all(executable)[source]

Search the path for an executable. Return all copies.

Parameters

executable (str) – Name of the executable

Returns

List[PathEntry]

find_all_python_versions(major=None, minor=None, patch=None, pre=None, dev=None, arch=None, name=None)[source]

Search for a specific python version on the path. Return all copies

Parameters
  • major (int) – Major python version to search for.

  • minor (int) – Minor python version to search for, defaults to None

  • patch (int) – Patch python version to search for, defaults to None

  • pre (bool) – Search for prereleases (default None) - prioritize releases if None

  • dev (bool) – Search for devreleases (default None) - prioritize releases if None

  • arch (str) – Architecture to include, e.g. ‘64bit’, defaults to None

  • name (str) – The name of a python version, e.g. anaconda3-5.3.0

Returns

A list of PathEntry instances matching the version requested.

Return type

List[PathEntry]

find_python_version(major=None, minor=None, patch=None, pre=None, dev=None, arch=None, name=None, sort_by_path=False)[source]

Search for a specific python version on the path.

Parameters
  • major (int) – Major python version to search for.

  • minor (int) – Minor python version to search for, defaults to None

  • patch (int) – Patch python version to search for, defaults to None

  • pre (bool) – Search for prereleases (default None) - prioritize releases if None

  • dev (bool) – Search for devreleases (default None) - prioritize releases if None

  • arch (str) – Architecture to include, e.g. ‘64bit’, defaults to None

  • name (str) – The name of a python version, e.g. anaconda3-5.3.0

  • sort_by_path (bool) – Whether to sort by path – default sort is by version(default: False)

Returns

A PathEntry instance matching the version requested.

Return type

PathEntry

property finders
get_path(path)[source]
get_pythons(finder)[source]
path_entries
python_executables
reload_finder(finder_name)[source]
version_dict
which(executable)[source]

Search for an executable on the path.

Parameters

executable (str) – Name of the executable to be located.

Returns

PathEntry object.

class pythonfinder.WindowsFinder(paths=NOTHING, version_list=NOTHING, versions=NOTHING, pythons=NOTHING)[source]

Bases: pythonfinder.models.mixins.BaseFinder

classmethod create(*args, **kwargs)[source]
find_all_python_versions(major=None, minor=None, patch=None, pre=None, dev=None, arch=None, name=None)[source]
find_python_version(major=None, minor=None, patch=None, pre=None, dev=None, arch=None, name=None)[source]
get_pythons()[source]
get_versions()[source]

Return the available versions from the finder

property pythons
property versions