Cmake 无法找到 Python 库 [英] Cmake is not able to find Python-libraries
问题描述
出现此错误:
sudo: unable to resolve host coderw@ll
-- Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS)
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:108
(message):
Could NOT find PythonInterp (missing: PYTHON_EXECUTABLE)
Call Stack (most recent call first):
/usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:315
(_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-2.8/Modules/FindPythonInterp.cmake:139
(FIND_PACKAGE_HANDLE_STANDARD_ARGS)
Code/cmake/Modules/FindNumPy.cmake:10 (find_package)
CMakeLists.txt:114 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/coderwall/Desktop/rdkit/build/CMakeFiles/CMakeOutput.log".
See also "/home/coderwall/Desktop/rdkit/build/CMakeFiles/CMakeError.log".
我已经安装了:
- sudo apt-get install python-dev
环境变量已经设置如下:
- sudo apt-get install python-dev
Environment variable are already set as follow:
PYTHON_INCLUDE_DIRS=/usr/include/python2.7
PYTHON_LIBRARIES=/usr/lib/python2.7/config/libpython2.7.so
python.h
的位置:/usr/lib/include/python2.7/python.h
python
库的位置:/usr/lib/python2.7/
如何解决这个问题?
Location of python
libs: /usr/lib/python2.7/
How to solve this?
推荐答案
您可以通过将 -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.
这篇关于Cmake 无法找到 Python 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!