[Python] 【python】Python: Could NOT find PythonLibs (如何查找你的python路径))

59 0
Honkers 4 小时前 | 显示全部楼层 |阅读模式

查找python对应lib和inc

1. 背景

使用cmake编译文件的时候报错

  1. CMake Error at /usr/local/share/cmake-3.14/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
  2. Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS)
复制代码

2. 解决方法

如果是anaconda激活对应的环境,如果不是,直接在终端中输入python或者python3 (需要决定需要查找的python版本)

如果是python 2版本, 输入以下代码

  1. root@c10fab84fca7:/usr/Downloads/felaim# python
  2. Python 2.7.12 (default, Dec 4 2017, 14:50:18)
  3. [GCC 5.4.0 20160609] on linux2
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>> from distutils.sysconfig import get_python_inc
  6. >>> print(get_python_inc())
  7. /usr/include/python2.7
  8. >>> import distutils.sysconfig as sysconfig
  9. >>> print(sysconfig.get_config_var('LIBDIR'))
  10. /usr/lib
  11. >>>
复制代码

可以看到python的include文件在

  1. /usr/include/python2.7
复制代码

python的lib文件在

  1. /usr/lib
复制代码

python3的同理

最后在编译的时候添加上对应的参数设置

  1. cmake -DPYTHON_INCLUDE_DIR=/usr/include/python2.7 -DPYTHON_LIBRARY=/usr/lib
复制代码

或者直接这样写

  1. $ cmake .. \
  2. -DPYTHON_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
  3. -DPYTHON_LIBRARY=$(python -c "import distutils.sysconfig as sysconfig; print(sysconfig.get_config_var('LIBDIR'))")
复制代码

如果是anaconda要激活对应环境运行.

参考地址

  1. https://stackoverflow.com/questions/24174394/cmake-is-not-able-to-find-python-libraries
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2026 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行天