1

I am using cmake version 3.17 on windows with the following code to find the Python3 interpreter.

set(Python3_FIND_VIRTUALENV FIRST)
find_package(Python3 REQUIRED COMPONENTS Interpreter)

For the python3 virtual environment, it fails with the following error

CMake Error at D:/.conan/b17c57/1/share/cmake-3.17/Modules/FindPython/Support.cmake:1313 (list):
  list index: 10 out of range (-10, 9)
Call Stack (most recent call first):
  D:/.conan/b17c57/1/share/cmake-3.17/Modules/FindPython3.cmake:311 (include)

I tried to print the values of _Python3_INTERPRETER_PROPERTIES for which the indexing is failing.

0:Python
1:3
2:6
3:6
4:64
5:cp36-win_amd64
6:C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Lib
7:C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Lib
8:D:\work\projects\devops\cip\temp\cip_build_system\venv\Lib\site-packages
9:D:\work\projects\devops\cip\temp\cip_build_system\venv\Lib\site-packages
CMake Error at D:/.conan/b17c57/1/share/cmake-3.17/Modules/FindPython/Support.cmake:1297 (list):
  list index: 10 out of range (-10, 9)

when I replaced it with find_package(PythonInterp 3.5 REQUIRED) it works fine with following values for _Python3_INTERPRETER_PROPERTIES

0:Python
1:3
2:6
3:6
4:64
5:
6:cp36-win_amd64
7:C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Lib
8:C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Lib
9:D:\work\projects\devops\cip\temp\cip_build_system\venv\Lib\site-packages
10:D:\work\projects\devops\cip\temp\cip_build_system\venv\Lib\site-packages

In the error case Python3_SOABI is missing. Any idea how can I fix this since PythonInterp is deprecated since cmake version 3.12?

Sirish
  • 9,183
  • 22
  • 72
  • 107
  • 1
    In the error case `_Python3_ABIFLAGS` is missing, SOABI is `cp36-win_amd64` in both cases. [Another question](https://stackoverflow.com/questions/72891805/cmake-findpython3-cmake-report-a-out-of-range-bug) has been asked recently about the same error message but with newer CMake (and Python). But its value of `_Python3_INTERPRETER_PROPERTIES` resembles your second case, when the element for ABIFLAGS is **empty**. BTW, `find_package(PythonInterp)` doesn't use the module `FindPython/Support.cmake` at all. Not sure why `_Python3_INTERPRETER_PROPERTIES` has been changed in the second case... – Tsyvarev Jul 09 '22 at 09:24

0 Answers0