Find Python 3 interpreter, compiler and development environment (include directories and libraries).
The following components are supported:
If no COMPONENTS are specified, Interpreter is assumed.
If component Development is specified, it implies sub-components Development.Module and Development.Embed.
To ensure consistent versions between components Interpreter, Compiler, Development (or one of its sub-components) and NumPy, specify all components at the same time:
find_package (Python3 COMPONENTS Interpreter Development)
This module looks only for version 3 of Python. This module can be used concurrently with FindPython2 module to use both Python versions.
The FindPython module can be used if Python version does not matter for you.
Note
If components Interpreter and Development (or one of its sub-components) are both specified, this module search only for interpreter with same platform architecture as the one defined by CMake configuration. This contraint does not apply if only Interpreter component is specified.
This module defines the following Imported Targets (when CMAKE_ROLE is PROJECT):
This module will set the following variables in your project (see Standard Variable Names):
Standard platform independent installation directory.
Information returned by distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=True) or else sysconfig.get_path('stdlib').
Standard platform dependent installation directory.
Information returned by distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=True) or else sysconfig.get_path('platstdlib').
Third-party platform independent installation directory.
Information returned by distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=False) or else sysconfig.get_path('purelib').
Third-party platform dependent installation directory.
Information returned by distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=False) or else sysconfig.get_path('platlib').
Extension suffix for modules.
Information returned by distutils.sysconfig.get_config_var('SOABI') or computed from distutils.sysconfig.get_config_var('EXT_SUFFIX') or python3-config --extension-suffix. If package distutils.sysconfig is not available, sysconfig.get_config_var('SOABI') or sysconfig.get_config_var('EXT_SUFFIX') are used.
This variable defines which ABIs, as defined in PEP 3149, should be searched.
Note
If Python3_FIND_ABI is not defined, any ABI will be searched.
The Python3_FIND_ABI variable is a 3-tuple specifying, in that order, pydebug (d), pymalloc (m) and unicode (u) flags. Each element can be set to one of the following:
From this 3-tuple, various ABIs will be searched starting from the most specialized to the most general. Moreover, debug versions will be searched after non-debug ones.
For example, if we have:
set (Python3_FIND_ABI "ON" "ANY" "ANY")
The following flags combinations will be appended, in that order, to the artifact names: dmu, dm, du, and d.
And to search any possible ABIs:
set (Python3_FIND_ABI "ANY" "ANY" "ANY")
The following combinations, in that order, will be used: mu, m, u, <empty>, dmu, dm, du and d.
Note
This hint is useful only on POSIX systems. So, on Windows systems, when Python3_FIND_ABI is defined, Python distributions from python.org will be found only if value for each flag is OFF or ANY.
This variable defines how lookup will be done. The Python3_FIND_STRATEGY variable can be set to one of the following:
On Windows the Python3_FIND_REGISTRY variable determine the order of preference between registry and environment variables. The Python3_FIND_REGISTRY variable can be set to one of the following:
On macOS the Python3_FIND_FRAMEWORK variable determine the order of preference between Apple-style and unix-style package components. This variable can take same values as CMAKE_FIND_FRAMEWORK variable.
Note
Value ONLY is not supported so FIRST will be used instead.
If Python3_FIND_FRAMEWORK is not defined, CMAKE_FIND_FRAMEWORK variable will be used, if any.
This variable defines the handling of virtual environments managed by virtualenv or conda. It is meaningful only when a virtual environment is active (i.e. the activate script has been evaluated). In this case, it takes precedence over Python3_FIND_REGISTRY and CMAKE_FIND_FRAMEWORK variables. The Python3_FIND_VIRTUALENV variable can be set to one of the following:
Note
If the component Development is requested, it is strongly recommended to also include the component Interpreter to get expected result.
This variable defines, in an ordered list, the different implementations which will be searched. The Python3_FIND_IMPLEMENTATIONS variable can hold the following values:
The default value is:
Note
This hint has the lowest priority of all hints, so even if, for example, you specify IronPython first and CPython in second, a python product based on CPython can be selected because, for example with Python3_FIND_STRATEGY=LOCATION, each location will be search first for IronPython and second for CPython.
Note
When IronPython is specified, on platforms other than Windows, the .Net interpreter (i.e. mono command) is expected to be available through the PATH variable.
To solve special cases, it is possible to specify directly the artifacts by setting the following variables:
Note
All paths must be absolute. Any artifact specified with a relative path will be ignored.
Note
When an artifact is specified, all HINTS will be ignored and no search will be performed for this artifact.
If more than one artifact is specified, it is the user’s responsability to ensure the consistency of the various artifacts.
By default, this module supports multiple calls in different directories of a project with different version/component requirements while providing correct and consistent results for each call. To support this behavior, CMake cache is not used in the traditional way which can be problematic for interactive specification. So, to enable also interactive specification, module behavior can be controled with the following variable:
Selects the behavior of the module. This is a boolean variable:
This module defines the command Python3_add_library (when CMAKE_ROLE is PROJECT), which has the same semantics as add_library() and adds a dependency to target Python3::Python or, when library type is MODULE, to target Python3::Module and takes care of Python module naming rules:
Python3_add_library (<name> [STATIC | SHARED | MODULE [WITH_SOABI]]
<source1> [<source2> ...])
If the library type is not specified, MODULE is assumed.
For MODULE library type, if option WITH_SOABI is specified, the module suffix will include the Python3_SOABI value, if any.