1

I am using CMake to find Python3, and my CMakeLists.txt is:

find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
include_directories(${Python3_INCLUDE_DIRS})
link_libraries(${Python3_LIBRARIES})

After configure, a bug is reported:

CMake Error at D:/Program Files/CMake/share/cmake-3.22/Modules/FindPython/Support.cmake:1832 (list):
  list index: 10 out of range (-10, 9)
Call Stack (most recent call first):
  D:/Program Files/CMake/share/cmake-3.22/Modules/FindPython3.cmake:490 (include)
  CMakeLists.txt:2 (find_package)

My environment is:

win 10
vs2022 x64
Python 3.7.0
Anaconda

How to fix this bug? Any suggestion is appreciated~~~


Update:

_Python3_INTERPRETER_PROPERTIES:INTERNAL=Python;3;10;5;64;;cp310-win_amd64;D:\Python-3.10.5\Lib;D:\Python-3.10.5\Lib;D:\Python-3.10.5\Lib\site-packages;D:\Python-3.10.5\Lib\site-packages
Qiang Zhang
  • 820
  • 8
  • 32
  • The error is about using `list(GET)` command at [Modules/FindPython/Support.cmake:1832](https://github.com/Kitware/CMake/blob/v3.22.1/Modules/FindPython/Support.cmake#L1832). It tries to extract an element with index 10 from the list variable `_Python3_INTERPRETER_PROPERTIES` and CMake reports that given list has only 10 elements, not 11. Actually, this variable is cached, you can found its value in `CMakeCache.txt` file under build directory. Please, add to the question post the exact value of that variable. – Tsyvarev Jul 07 '22 at 07:17
  • I have show the value of `_Python3_INTERPRETER_PROPERTIES` in my post. How can I fix this bug? – Qiang Zhang Jul 09 '22 at 01:25
  • Given value, with double semicolon after `64`, looks correct. E.g. in the mini-example I was able to retrieve its 10-th elemen using `list(GET)`. Not sure what is a problem. BTW, I have found [a question](https://stackoverflow.com/questions/65029672/find-package-python3-error-on-windows-with-missing-python3-soabi) about the same error message with older CMake (and Python). But content of `_Python3_INTERPRETER_PROPERTIES` variable matches to the second (successfull) case, not to the first (failed)... – Tsyvarev Jul 09 '22 at 09:07
  • I find the bug is fixed after adding `cmake_minimum_required(VERSION 3.20.0)`. – Qiang Zhang Jul 09 '22 at 11:09

0 Answers0