背景建模库bgslibrary使用pipenv虚拟python库编译(CMakeLists.txt指定python库)

源码链接:https://github.com/andrewssobral/bgslibrary

该集成库中给出了Linux中使用系统python和anaconda编译方法。博主尝试均能正确编译通过。

但博主习惯使用pipenv建立虚拟python环境,当使用虚拟环境库时cmake会出现如下问题:

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
PYTHON_LIBRARY (ADVANCED)
    linked by target "bgs_python" in directory /home/sh00245/py2env/bgslibrary

然后再CMakeLists.txt中查找相关内容,设置python lib库和bin档的主要部分为:

  message(STATUS "")
  message(STATUS "Python library status:")
  message(STATUS "    executable: ${PYTHON_EXECUTABLE}")
  message(STATUS "    library: ${PYTHON_LIBRARY}")
  message(STATUS "    include path: ${PYTHON_INCLUDE_DIRS}")

可见主要由参数PYTHON_EXECUTABLE负责制定python版本,即指向python的bin档,而PYTHON_LIBRARY则制定python中lib库,PYTHON_INCLUDE_DIRS制定python头文件。如此我们只需在cmake编译时强制制定为虚拟环境中的python相关路径即可。如下:

cmake -D BGS_PYTHON_SUPPORT=ON -D BGS_PYTHON_VERSION=2 -D PYTHON_EXECUTABLE=/home/sh00245/.virtualenvs/py2env-bXX-iFib/bin/python2.7 -D PYTHON_LIBRARY=/home/sh00245/.virtualenvs/py2env-bXX-iFib/lib ..

当然你也可在环境变量如bashrc中添加:

export PYTHON_EXECUTABLE=/路径/python
export PYTHON_LIBRARIES=/路径/lib

 

你可能感兴趣的:(python)