Find Python interpreter, compiler and development environment (include directories and libraries).
The following components are supported:
If no COMPONENTS are specified, Interpreter is assumed.
To ensure consistent versions between components Interpreter, Compiler, Development and NumPy, specify all components at the same time:
find_package (Python COMPONENTS Interpreter Development)
This module looks preferably for version 3 of Python. If not found, version 2 is searched. To manage concurrent versions 3 and 2 of Python, use FindPython3 and FindPython2 modules rather than this one.
Note
If components Interpreter and Development 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).
Standard platform dependent installation directory.
Information returned by distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=True).
Third-party platform independent installation directory.
Information returned by distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=False).
Third-party platform dependent installation directory.
Information returned by distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=False).
Extension suffix for modules.
Information returned by distutils.sysconfig.get_config_flag('SOABI') or computed from distutils.sysconfig.get_config_flag('EXT_SUFFIX') or python-config --extension-suffix.
This variable defines which ABIs, as defined in PEP 3149, should be searched.
Note
This hint will be honored only when searched for Python version 3.
Note
If Python_FIND_ABI is not defined, any ABI will be searched.
The Python_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 (Python_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 (Python_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 Python_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 Python_FIND_STRATEGY variable can be set to one of the following:
On Windows the Python_FIND_REGISTRY variable determine the order of preference between registry and environment variables. the Python_FIND_REGISTRY variable can be set to one of the following:
On macOS the Python_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 Python_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 Python_FIND_REGISTRY and CMAKE_FIND_FRAMEWORK variables. The Python_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.
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.
This module defines the command Python_add_library (when CMAKE_ROLE is PROJECT), which has the same semantics as add_library() and adds a dependency to target Python::Python or, when library type is MODULE, to target Python::Module and takes care of Python module naming rules:
Python_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 Python_SOABI value, if any.