Cmake is not able to find Python-libraries

后端 未结 10 1496
太阳男子
太阳男子 2020-12-02 16:53

Getting this error:

sudo: unable to resolve host coderw@ll
-- Could NOT find PythonLibs (missing:  PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS) 
CMake Error at /usr         


        
相关标签:
10条回答
  • 2020-12-02 17:18

    For me was helpful next:

    > apt-get install python-dev python3-dev
    
    0 讨论(0)
  • 2020-12-02 17:19

    I was facing this problem while trying to compile OpenCV 3 on a Xubuntu 14.04 Thrusty Tahr system. With all the dev packages of Python installed, the configuration process was always returning the message:

    Could NOT found PythonInterp: /usr/bin/python2.7 (found suitable version "2.7.6", minimum required is "2.7")
    Could NOT find PythonLibs (missing: PYTHON_INCLUDE_DIRS) (found suitable exact version "2.7.6")
    Found PythonInterp: /usr/bin/python3.4 (found suitable version "3.4", minimum required is "3.4")
    Could NOT find PythonLibs (missing: PYTHON_LIBRARIES) (Required is exact version "3.4.0")
    

    The CMake version available on Thrusty Tahr repositories is 2.8. Some posts inspired me to upgrade CMake. I've added a PPA CMake repository which installs CMake version 3.2.

    After the upgrade everything ran smoothly and the compilation was successful.

    0 讨论(0)
  • 2020-12-02 17:19

    In case that might help, I found a workaround for a similar problem, looking at the cmake doc : https://cmake.org/cmake/help/v3.0/module/FindPythonLibs.html

    You must set two env vars for cmake to find coherent versions. Unfortunately this is not a generic solution...

    cmake -DPYTHON_LIBRARY=${HOME}/.pyenv/versions/3.8.0/lib/libpython3.8.a -DPYTHON_INCLUDE_DIR=${HOME}/.pyenv/versions/3.8.0/include/python3.8/ cern_root/
    
    0 讨论(0)
  • 2020-12-02 17:25

    Note that if you are using cMake version 3.12 or later, variable PythonInterp and PythonLibs has been changed into Python.

    So we use:

    find_package(Python ${PY_VERSION} REQUIRED)

    instead of:

    find_package(PythonInterp ${PY_VERSION} REQUIRED) find_package(PythonLibs ${PY_VERSION} REQUIRED)

    see https://cmake.org/cmake/help/v3.12/module/FindPython.html for details.

    0 讨论(0)
  • 2020-12-02 17:29

    I hit the same issue,and discovered the error message gives misleading variable names. Try setting the following (singular instead of plural):

    PYTHON_INCLUDE_DIR=/usr/include/python2.7 
    PYTHON_LIBRARY=/usr/lib/python2.7/config/libpython2.7.so
    

    The (plural) variables you see error messages about are values that the PythonLibs sets up when it is initialised correctly.

    0 讨论(0)
  • 2020-12-02 17:30

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

    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'))")
    

    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 ....

    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.

    0 讨论(0)
提交回复
热议问题