[转载] Imported target “pybind11::module“ includes non-existent path + Python路径指定错误

CMakeLists.txt

cmake_minimum_required(VERSION 3.18)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

project(xiaoHelloWorld)

add_subdirectory(extern/pybind11)

pybind11_add_module(xiaoHelloWorld xiao.cpp)
mkdir build
cd build
cmake ..
make check -j 4

报错错误大意是 cmake 不能找到正确的Python版本.

CMake Error in CMakeLists.txt:
  Imported target "pybind11::module" includes non-existent path

    "/usr/include/python3.6m"

  in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:

  * The path was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and references files it does not
  provide.

给cmake参数指定一下 Python 路径就行

 -DPYTHON_EXECUTABLE=~/opt/anaconda3/bin/python 

不知道在哪的话,就:

$ which python
/usr/bin/python
$ cmake .. -DPYTHON_EXECUTABLE=/usr/bin/python

参考自:
https://bitbucket.org/mituq/muq2/issues/23/imported-target-pybind11-module-includes

你可能感兴趣的:(python,开发语言)