@@ -242,6 +242,39 @@ that that were ``malloc()``-ed in another shared library, using data
242242structures with incompatible ABIs, and so on. pybind11 is very careful not
243243to make these types of mistakes.
244244
245+ Inconsistent detection of Python version in CMake and pybind11
246+ ==============================================================
247+
248+ The functions ``find_package(PythonInterp) `` and ``find_package(PythonLibs) `` provided by CMake
249+ for Python version detection are not used by pybind11 due to unreliability and limitations that make
250+ them unsuitable for pybind11's needs. Instead pybind provides its own, more reliable Python detection
251+ CMake code. Conflicts can arise, however, when using pybind11 in a project that *also * uses the CMake
252+ Python detection in a system with several Python versions installed.
253+
254+ This difference may cause inconsistencies and errors if *both * mechanisms are used in the same project. Consider the following
255+ Cmake code executed in a system with Python 2.7 and 3.x installed:
256+
257+ .. code-block :: cmake
258+
259+ find_package(PythonInterp)
260+ find_package(PythonLibs)
261+ find_package(pybind11)
262+
263+ It will detect Python 2.7 and pybind11 will pick it as well.
264+
265+ In contrast this code:
266+
267+ .. code-block :: cmake
268+
269+ find_package(pybind11)
270+ find_package(PythonInterp)
271+ find_package(PythonLibs)
272+
273+ will detect Python 3.x for pybind11 and may crash on ``find_package(PythonLibs) `` afterwards.
274+
275+ It is advised to avoid using ``find_package(PythonInterp) `` and ``find_package(PythonLibs) `` from CMake and rely
276+ on pybind11 in detecting Python version. If this is not possible CMake machinery should be called *before * including pybind11.
277+
245278How to cite this project?
246279=========================
247280
@@ -256,4 +289,3 @@ discourse:
256289 note = {https://github.com/pybind/pybind11},
257290 title = {pybind11 -- Seamless operability between C++11 and Python}
258291 }
259-
0 commit comments