(venv 使えよっていうツッコミ is たぶん正しいです…)
状況
instant-ngp を入れようとして、cmake
してたら以下のエラー
CMake Error at /root/.pyenv/versions/3.9.17/envs/insngp/lib/python3.9/site-packages/cmake/data/share/cmake-3.26/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS)
Call Stack (most recent call first):
/root/.pyenv/versions/3.9.17/envs/insngp/lib/python3.9/site-packages/cmake/data/share/cmake-3.26/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
/root/.pyenv/versions/3.9.17/envs/insngp/lib/python3.9/site-packages/cmake/data/share/cmake-3.26/Modules/FindPythonLibs.cmake:310 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:232 (find_package)
見に行ってみると、CMakeLists.txt
の find_package
でエラーが出ていた。
find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
調べてると、
Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS)
このエラーは、python-dev
が入っていないことが原因っぽい。
普通に apt install python-3.9 python3.9-dev
とかで python を入れてたらこのエラーには出くわさないんだけど、pyenv を使ってたために出くわしてしまった…
ここで適当に apt install python-dev
をすると、pyenv の python に関係ない python-dev が入る気がした
実際、CMakeList.txt
で ↓ で print デバッグしてみると、 (GPTに教えてもらった)
find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
message(STATUS "Python libraries: ${PYTHON_LIBRARIES}")
message(STATUS "Python include directories: ${PYTHON_INCLUDE_DIRS}")
-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython2.7.so (found version "2.7.18")
-- Python libraries: /usr/lib/x86_64-linux-gnu/libpython2.7.so
と、python3.9 を使ってるのに見つかった PYTHON_LIBRARIES
と PYTHON_INCLUDE_DIRS
は python2.7 云々言ってて、ダメです!
ちなみに、いま使っている python 環境が使ってる header とか library の場所は以下で調べられるらしい (by GPT)
import distutils.sysconfig
print("Header files:", distutils.sysconfig.get_python_inc())
print("Library files:", distutils.sysconfig.get_config_var('LIBDIR'))
出力
Header files: /root/.pyenv/versions/3.9.17/include/python3.9
Library files: /root/.pyenv/versions/3.9.17/lib
pyenv で dev ぽいことする?
どうやら pyenv 環境を作るときの option で dev っぽいことができるらしい?(あんまよくわかってないす)
env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv virtualenv 3.9.17 insngp
で、 cmake
のときにオプションを渡す
cmake . -B build \
-D PYTHON_LIBRARIES=/root/.pyenv/versions/3.9.17/lib \
-D PYTHON_INCLUDE_DIRS=/root/.pyenv/versions/3.9.17/include/python3.9
&、CMakeList.txt の find_package
を消す
# find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
で通った