Title: CMake can not find PythonLibs
Tags: cmake
Question: I am trying to build inria Graphite on my ubuntu which is running in a VirtualBox simulator, I follow the instructions, and install the python-dev packages, but when I run cmake , still got an error:
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)
I checked the /usr/lib/ and find
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
so why cmake can not find the PythonLibs, or how should I deal with this?


Here is another answer: I recently had a similar issue with Ubuntu 14.04 64-bit; apparently, CMake does not look into architecture dependent install folders by default:
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&gt;/(lib/<arch&gt;|lib|share)/cmake/<name&gt;*/          (U)
<prefix&gt;/(lib/<arch&gt;|lib|share)/<name&gt;*/                (U)
<prefix&gt;/(lib/<arch&gt;|lib|share)/<name&gt;*/(cmake|CMake)/  (U)
In all cases the <name&gt; is treated as case-insensitive and corresponds to any of
the names specified (<package&gt; or names given by NAMES). Paths with lib/<arch&gt;
are enabled if CMAKE_LIBRARY_ARCHITECTURE is set.
(from CMake 2.8.12 online documentation of the find_package command)
A solution consists in setting this CMAKE_LIBRARY_ARCHITECTURE in the project root CMakeLists.txt file (in your case that would be editing src/packages/OGF/gel_python3/CMakeLists.txt) before calling find_package for PythonLibs; for instance:
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
That worked in my case.

Here is another answer: For me the issue was a bad cache
rm CMakeCache.txt
Removed the cache with the old 2.7 version and allowed it to find 3.2 in my case.
The cmake I used is
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})

Here is another answer: Installing python-dev actually fixed this for me:
sudo apt-get install python-dev
Got the hint here: https://github.com/Valloric/YouCompleteMe/issues/484
Comment for this answer: This does not solve the issue in all cases, the answer given by @Job explains why.
Comment for this answer: Caffe currently only takes 2.7 and won't cmake with python3. If you try to install python3-dev which installs python-is-python3, caffe still throws a `Could NOT find PythonLibs (Required is at least version "2.7")'.  You have to aptitude install python-is-python2 to back it out, and python-dev (version 2), in order for the Caffe cmake to work.
Comment for this answer: @minerals what answer given by Job?
Comment for this answer: A small note: for Python 3 use `apt-get install python3-dev`. `python-dev` and `python3-dev` are metapackages that pull the most current dev upstream for the selected Python.
Comment for this answer: @helgar Please [edit](http://askubuntu.com/posts/641432/edit) your answer and add the above command.
Comment for this answer: Rather than pointing to an external link please copy-paste the relevant portion from there so that if the link is unreachable for some reason the contents are still available here..
Comment for this answer: Well, the solution is to run: `sudo apt-get install python-dev`

Here is another answer: The problem seems to be that Ubuntu 14.04 installs Python 3.4 by default and the CMake version from Ubuntu (2.8) only searches up to Python 3.3. A workaround is to add set(Python_ADDITIONAL_VERSIONS 3.4) before the find_package statement. Note that I filed a bug about this issue.
Since CMake 3.0, CMake searches up to Python 3.4, so installing that version manually should also fix the problem.
Comment for this answer: It would be nice to give an explanation about the downvote.

{'source': 'StackExchangeDataset', 'subset': 'askubuntu.com', 'metadata': {'AnswerCount': 4, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2014:00:06/08/14', 'FavoriteCount': 6.0, 'PostTypeId': 1, 'Tags': '<cmake>', 'Title': 'CMake can not find PythonLibs', 'ViewCount': 61445, 'id': 479260, 'user_AboutMe': '<p>an undergraduate studying computer graphics at USTC,china</p>\n', 'user_AccountId': 1972958.0, 'user_DisplayName': 'tintin', 'user_Reputation': 271.0, 'user_Views': 8.0, 'user_id': 163337.0}}