CMake找不到PythonLib


14

我试图在正在VirtualBox模拟器中运行的ubuntu上构建inria Graphite,我按照说明进行操作,并安装了python-dev软件包,但是当我运行cmake时,仍然出现错误:

CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:108          (message):
Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS)
(Required is at least version "3.2")
Call Stack (most recent call first):
 /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:315     (_FPHSA_FAILURE_MESSAGE)
 /usr/share/cmake-2.8/Modules/FindPythonLibs.cmake:208 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
 src/packages/OGF/gel_python3/CMakeLists.txt:11 (FIND_PACKAGE)

我检查了/usr/lib/并找到

tintin@tintin-VirtualBox:/usr/lib$ find . -name "libpython*"
./x86_64-linux-gnu/libpython3.4m.so.1.0
./x86_64-linux-gnu/libpython2.7.so.1.0
./x86_64-linux-gnu/libpython3.4m.a
./x86_64-linux-gnu/libpython2.7.a
./x86_64-linux-gnu/libpython3.4m.so
./x86_64-linux-gnu/libpython2.7.so
./x86_64-linux-gnu/libpython2.7.so.1
./x86_64-linux-gnu/libpython3.4m.so.1

那么为什么cmake找不到PythonLib,或者我应该如何处理呢?

Answers:


21

安装python-dev实际上为我解决了这个问题:

sudo apt-get install python-dev

在这里得到提示:https : //github.com/Valloric/YouCompleteMe/issues/484


2
而不是指向外部链接,请从此处复制粘贴相关部分,以便如果由于某种原因无法访问该链接,则此处的内容仍然可用
。。– heemayl 2015年

1
好吧,解决方案是运行:sudo apt-get install python-dev
helgar 2015年

@helgar请编辑您的答案并添加以上命令。
罗恩

3
注意事项:适用于Python 3 apt-get install python3-devpython-dev并且python3-dev是元软件包,可将最新的开发人员拉到所选Python的上游。
rbaleksandar

这不能在所有情况下解决问题,@ Job给出的答案解释了原因。
矿物

10

问题似乎是Ubuntu 14.04默认安装Python 3.4,而Ubuntu(2.8)的CMake版本最多只能搜索Python 3.3。解决方法是set(Python_ADDITIONAL_VERSIONS 3.4)find_package语句之前添加。请注意,我提交了有关此问题的错误

从CMake 3.0开始,CMake最多搜索Python 3.4,因此手动安装该版本也可以解决此问题。


给出关于下降投票的解释会很好。
Job

3

对我来说,问题是缓存不好

rm CMakeCache.txt

在我的情况下,删除了旧版2.7的缓存,并允许它找到3.2。

我用的cmake是

find_package(PythonInterp 3.2 REQUIRED)
find_package(PythonLibs 3.2 REQUIRED)
message(STATUS "PYTHON_LIBRARIES = ${PYTHON_LIBRARIES}")
message(STATUS "PYTHON_EXECUTABLE = ${PYTHON_EXECUTABLE}")
message(STATUS "PYTHON_INCLUDE_DIRS = ${PYTHON_INCLUDE_DIRS}")
...
include_directories(${PYTHON_INCLUDE_DIRS})

1

最近,我在64位Ubuntu 14.04上遇到了类似的问题。显然,默认情况下,CMake不会调查依赖于体系结构的安装文件夹:

CMake constructs a set of possible installation prefixes for the package. Under
each prefix several directories are searched for a configuration file. The tables
below show the directories searched.

[...]

  <prefix>/(lib/<arch>|lib|share)/cmake/<name>*/          (U)
  <prefix>/(lib/<arch>|lib|share)/<name>*/                (U)
  <prefix>/(lib/<arch>|lib|share)/<name>*/(cmake|CMake)/  (U)

[...]

In all cases the <name> is treated as case-insensitive and corresponds to any of
the names specified (<package> or names given by NAMES). Paths with lib/<arch>
are enabled if CMAKE_LIBRARY_ARCHITECTURE is set.

(摘自find_package命令的 CMake 2.8.12联机文档)

一种解决方案是在为PythonLibs调用find_package之前,在项目根CMakeLists.txt文件(在您的情况下,将编辑src / packages / OGF / gel_python3 / CMakeLists.txt)中设置此CMAKE_LIBRARY_ARCHITECTURE;例如:

cmake_minimum_required(VERSION 2.8)
project(project_name)

# Check the architecture and set CMAKE_LIBRARY_ARCHITECTURE accordingly
if(UNIX)
  if(CMAKE_SIZEOF_VOID_P EQUAL 8)
    set(CMAKE_LIBRARY_ARCHITECTURE "x86_64-linux-gnu")
  endif()
endif()

find_package(PythonInterp 3.2 REQUIRED)
find_package(PythonLibs 3.2 REQUIRED)

# Rest of your file

在我看来,这是可行的。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.