且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Cmake 无法找到 Python 库

更新时间:2022-05-25 18:47:31

您可以通过将 -DPYTHON_LIBRARY- 添加到 cmake 命令来修复错误DPYTHON_INCLUDE_DIR 标记填充了各自的文件夹.

You can fix the errors by appending to the cmake command the -DPYTHON_LIBRARY and -DPYTHON_INCLUDE_DIR flags filled with the respective folders.

因此,诀窍是用python解释器返回的信息填充这些参数,这是最可靠的.这可能独立于您的 python 位置/版本(也适用于 Anaconda 用户):

Thus, the trick is to fill those parameters with the returned information from the python interpreter, which is the most reliable. This may work independently of your python location/version (also for Anaconda users):

$ cmake .. 
-DPYTHON_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())")  
-DPYTHON_LIBRARY=$(python -c "import distutils.sysconfig as sysconfig; print(sysconfig.get_config_var('LIBDIR'))")

如果你想链接到 cmake 的 python 版本是 Python3.X 并且默认的 python 符号链接指向 Python2.X,则可以使用 python3 -c ... 代替 python -c ....

If the version of python that you want to link against cmake is Python3.X and the default python symlink points to Python2.X, python3 -c ... can be used instead of python -c ....

如果错误仍然存​​在,您可能需要将 cmake 更新到@pdpcosta 所述的更高版本,然后再次重复该过程.

In case that the error persists, you may need to update the cmake to a higher version as stated by @pdpcosta and repeat the process again.