-1

I have both Python 3.6 in "C:\PYTHON_VERSIONS\STANDARD_3.6.8" and 3.8 in "C:\Python\3.8" in my system. I want to compile pybind11 using 3.6 but CMake takes lib directories from 3.6 and the executable from 3.8! a very bad mix indeed.

Here is output of CMake:

-- Found PythonInterp: C:/Python/3.8/python.exe (found version "3.8.9") 
-- Found PythonInterp: C:/Python/3.8/python.exe (found suitable version "3.8.9", minimum required is "3.6") 
CMake Error at C:/work/packgen/rsdist/pybind11/tools/FindPythonLibsNew.cmake:147 (message):
  Python config failure:

  Traceback (most recent call last):

    File "<string>", line 6, in <module>
    File "C:\PYTHON_VERSIONS\STANDARD_3.6.8\lib\distutils\sysconfig.py", line 14, in <module>
      import re
    File "C:\PYTHON_VERSIONS\STANDARD_3.6.8\lib\re.py", line 123, in <module>
      import sre_compile
    File "C:\PYTHON_VERSIONS\STANDARD_3.6.8\lib\sre_compile.py", line 17, in <module>
      assert _sre.MAGIC == MAGIC, "SRE module mismatch"

  AssertionError: SRE module mismatch

Call Stack (most recent call first):
  CMakeLists.txt:25 (find_package)

I have in my environment variables PYTHONHOME and PYTHONPATH to the 3.6 folder: enter image description here

And in the "path" variable itself there are no paths to any of the python installation folders.

So the question is: How does CMake finds executable that is not in the path, and mixes executable and libs of different versions?

Is there something like CMAKE_SET_PYTHON_PATH or something that I force feed it into CMake?

DEKKER
  • 877
  • 6
  • 19

1 Answers1

-1

The first thing you can do is consider specifying a version constraint in the find_package command call.

Besides that, the FindPython module has some hints variables, which you can try using. Of particular interest is probably Python_ROOT_DIR. Quoting from the docs:

Python_ROOT_DIR:
Define the root directory of a Python installation.

You could try setting that as a cache variable in your configure command using -D. Ex -DPython_ROOT_DIR=C:\PYTHON_VERSIONS\STANDARD_3.6.8.

You might also be interested in the Python_FIND_ABI and Python_FIND_STRATEGY hint variables. If you want the latest version in the fitting search locations to be used, then set Python_FIND_STRATEGY to VERSION.

See also the corresponding docs if you're using the FindPython3 module instead of the FindPython module (and make sure to adjust the hint variable names accordingly if this is the case).

starball
  • 20,030
  • 7
  • 43
  • 238