Repository: bulletphysics/bullet3

Issue:
Could NOT find PythonLibs (missing:  PYTHON_LIBRARIES) (found suitable exact version "2.7.12")
Could NOT find PythonLibs (missing:  PYTHON_LIBRARIES) (found suitable exact version "2.7.12")


Discussion:
cmake's find mechanism 'find' doesn't work well.  See also pull request 1131 (https://github.com/bulletphysics/bullet3/pull/1131)
You can use "pip install -e ." in the root of Bullet, or simply use pip install pybullet for now.
The correct command line parameters need to be specified. If, for example, a path to the python interpreter and the python library are found and the versions do not match exactly the cmake script will correctly report an error. Here is the most recent command I built with via CMake, but it was some time ago so I can't say it is perfect and working on master, but it might help with figuring out what to do.

```
cmake .. -DCMAKE_C_FLAGS_RELEASE=-DNDEBUG -DCMAKE_CXX_FLAGS_RELEASE=-DNDEBUG -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/bullet/2.86.1_1 -DCMAKE_BUILD_TYPE=Release -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_VERBOSE_MAKEFILE=ON -Wno-dev -DHAVE_CLOCK_GETTIME:INTERNAL=0 -DINSTALL_EXTRA_LIBS=ON -DBUILD_UNIT_TESTS=OFF -DUSE_DOUBLE_PRECISION=ON -DBUILD_BULLET2_DEMOS=ON -DBUILD_PYBULLET_MAC_USE_PYTHON_FRAMEWORK=ON -DBUILD_PYBULLET=ON -DBUILD_PYBULLET_NUMPY=ON -DBUILD_PYBULLET_CLSOCKET=ON -DBUILD_PYBULLET_ENET=ON -DPYTHON_EXECUTABLE=/usr/local/opt/python/bin/python -DPYTHON_LIBRARIES=/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib -DPYTHON_INCLUDE_DIRS=/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/include/python2.7 -DPYTHON_NUMPY_INCLUDE_DIR=/usr/local/lib/python2.7/site-packages/numpy/core/include -DBUILD_ENET=ON -DBUILD_CLSOCKET=ON -DBUILD_SHARED_LIBS=ON -DFRAMEWORK=OFF -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/bullet/2.86.1_1/Frameworks -DCMAKE_INSTALL_NAME_DIR=/usr/local/Cellar/bullet/2.86.1_1/Frameworks
```

This is very important because before #1131 it would find inconsistent versions and proceed to build and install, but fail to run in hard to diagnose ways. At least here it is very explicit, though perhaps more documentation and automated scripts to configure it correctly by default would be helpful.
There must be some sane find python cmake script out there that automates all this, without having to specify it, right? Having to tell cmake exactly all those details defeats the purpose of a find Python script.
> There must be some sane find python cmake script out there that automates all this, without having to specify it, right? Having to tell cmake exactly all those details defeats the purpose of a find Python script.

I sure hope so... I incorporated the best one I could find with a compatible license. I'm sorry I don't have anything better off hand.
Also, the message is really odd:
>> found suitable exact version "2.7.12"

exact version of what? The binaries? The libraries?

So why doesn't it use this suitable exact version, if it found it?

I'll try to re-enable building of python in travis here, let's see what the error is:
https://github.com/bulletphysics/bullet3/pull/1323
>>I incorporated the best one I could find with a compatible license.

yes, I didn't mean to blame you. It is frustrating that finding Python is such a pain with cmake. 

That was one more reason why I moved to using pip/setuptools, at least that seems to work smooth. Also, it becomes a single command to install pybullet (pip install pybullet, or python setup.py develop in the root of Bullet)
If we cannot make the travis work, I will revert to the old way of finding python. If that doesn't work for you, please use pip / setuptools.
unfortunately, the old way is more broken... If you simply update the travis cmake command with the correct paths to the various components like in my comment above https://github.com/bulletphysics/bullet3/issues/1322#issuecomment-330395455, I expect it should work. I've been using the cmake build for quite some time without problems.

I can see the problem is almost certainly at https://github.com/bulletphysics/bullet3/blob/master/.travis.yml#L16, it does not specify the location of python, the version of python, or anything else.

If you don't want that to be necessary, update the internal defaults to match whatever configuration travis is using.
Here is a second example in case that helps, this is for mac so obviously the paths would need to be updated for linux and the mac only flags would need to be removed:

```
± cmake .. -DCMAKE_C_FLAGS_RELEASE=-DNDEBUG -DCMAKE_CXX_FLAGS_RELEASE=-DNDEBUG -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/bullet/HEAD-47eae8d_1 -DCMAKE_BUILD_TYPE=Release -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_VERBOSE_MAKEFILE=ON -Wno-dev -DHAVE_CLOCK_GETTIME:INTERNAL=0 -DINSTALL_EXTRA_LIBS=ON -DBUILD_UNIT_TESTS=OFF -DUSE_DOUBLE_PRECISION=ON -DBUILD_PYBULLET_MAC_USE_PYTHON_FRAMEWORK=ON -DBUILD_PYBULLET=ON -DBUILD_PYBULLET_MAC_USE_PYTHON_FRAMEWORK=ON -DBUILD_PYBULLET_NUMPY=ON -DBUILD_PYBULLET_CLSOCKET=ON -DBUILD_PYBULLET_ENET=ON -DBUILD_ENET=ON -DBUILD_CLSOCKET=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_BULLET2_DEMOS=OFF -DPYTHON_NUMPY_INCLUDE_DIR=/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/include/python2.7
```
Having to specify where python is defeats the purpose of a 'find' script, unless you have multiple versions of Python. Travis machines only have 1 Python version by default. Luckily the 'find_package' finds Python libs and include paths just fine on Travis and that's important to make sure things are build properly. 

Wouldn't the current 'find' python script work fine if you provide all variables explicitly?

Does your line work with the current version of Bullet ('old' cmake)? If not, why not?
Oh wait, all my configuration code that found specific versions and set things up consistently was removed in https://github.com/bulletphysics/bullet3/commit/03cde2ee9bed76c186a1507be6319328c3bf728c, in that case it makes perfect sense that things don't work!

What happened to the changes in https://github.com/bulletphysics/bullet3/pull/1131?


Patch:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8e5f009df2..8d692e89b5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -301,8 +301,25 @@ IF (APPLE)
 ENDIF()
 
 OPTION(BUILD_BULLET3 "Set when you want to build Bullet 3" ON)
-
-OPTION(BUILD_PYBULLET "Set when you want to build pybullet (Python bindings for Bullet)" OFF)
+# Optional Python configuration
+# builds pybullet automatically if all the requirements are met
+SET(PYTHON_VERSION_PYBULLET "2.7" CACHE STRING "Python version pybullet will use.")
+SET(Python_ADDITIONAL_VERSIONS 2.7 2.7.3 2.7.12 3 3.0 3.1 3.2 3.3 3.4 3.5 3.6)
+SET_PROPERTY(CACHE PYTHON_VERSION_PYBULLET PROPERTY STRINGS ${Python_ADDITIONAL_VERSIONS})
+SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/build3/cmake ${CMAKE_MODULE_PATH})
+OPTION(EXACT_PYTHON_VERSION "Require Python and match PYTHON_VERSION_PYBULLET exactly, e.g. 2.7.12" OFF)
+IF(EXACT_PYTHON_VERSION)
+  set(EXACT_PYTHON_VERSION_FLAG EXACT REQUIRED)
+ENDIF(EXACT_PYTHON_VERSION)
+# first find the python interpreter
+FIND_PACKAGE(PythonInterp ${PYTHON_VERSION_PYBULLET} ${EXACT_PYTHON_VERSION_FLAG})
+# python library should exactly match that of the interpreter
+FIND_PACKAGE(PythonLibs ${PYTHON_VERSION_STRING} EXACT)
+SET(DEFAULT_BUILD_PYBULLET OFF)
+IF(PYTHONLIBS_FOUND)
+	SET(DEFAULT_BUILD_PYBULLET ON)
+ENDIF(PYTHONLIBS_FOUND)
+OPTION(BUILD_PYBULLET "Set when you want to build pybullet (Python bindings for Bullet)" ${DEFAULT_BUILD_PYBULLET})
 
 OPTION(BUILD_ENET "Set when you want to build apps with enet UDP networking support" ON)
 OPTION(BUILD_CLSOCKET "Set when you want to build apps with enet TCP networking support" ON)
@@ -310,7 +327,7 @@ OPTION(BUILD_CLSOCKET "Set when you want to build apps with enet TCP networking
 
 IF(BUILD_PYBULLET)
 	FIND_PACKAGE(PythonLibs)
-	
+
 	OPTION(BUILD_PYBULLET_NUMPY "Set when you want to build pybullet with NumPy support" OFF)
 	OPTION(BUILD_PYBULLET_ENET "Set when you want to build pybullet with enet UDP networking support" ON)
 	OPTION(BUILD_PYBULLET_CLSOCKET "Set when you want to build pybullet with enet TCP networking support" ON)
diff --git a/build3/cmake/FindPythonLibs.cmake b/build3/cmake/FindPythonLibs.cmake
index a0e9bffbeb..b0bcd839ca 100644
--- a/build3/cmake/FindPythonLibs.cmake
+++ b/build3/cmake/FindPythonLibs.cmake
@@ -64,7 +64,7 @@ if(EXISTS "${PYTHON_INCLUDE_DIR}" AND EXISTS "${PYTHON_LIBRARY}")
 else()
   set(_PYTHON1_VERSIONS 1.6 1.5)
   set(_PYTHON2_VERSIONS 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0)
-  set(_PYTHON3_VERSIONS 3.4 3.3 3.2 3.1 3.0)
+  set(_PYTHON3_VERSIONS 3.6 3.5 3.4 3.3 3.2 3.1 3.0)
 
   unset(_PYTHON_FIND_OTHER_VERSIONS)
   if(PythonLibs_FIND_VERSION)
@@ -176,12 +176,13 @@ else()
               FIND_LIBRARY(PYTHON_LIBRARY
                 NAMES ${_PYTHON_LIBRARY_NAMES}
                 PATH_SUFFIXES
-                python${_PYTHON_SHORT_VERSION}/config
-                python${_PYTHON_SHORT_VERSION_NO_DOT}/config
+                "python${_PYTHON_SHORT_VERSION}/config"
+                "python${_PYTHON_SHORT_VERSION_NO_DOT}/config"
                 PATHS
                 ${_PYTHON_LIBRARY_DIR}
-                ${_PYTHON_PREFIX}/lib $
-                {_PYTHON_PREFIX}/libs
+                ${_PYTHON_PREFIX}/lib
+                ${_PYTHON_PREFIX}/libs
+                ${_PYTHON_LIBRARY_DIR}/x86_64-linux-gnu/
                 NO_DEFAULT_PATH)
 
               if(WIN32)
@@ -254,6 +255,10 @@ set(PYTHON_LIBRARY_DEBUG "${PYTHON_DEBUG_LIBRARY}")
 set(PYTHON_LIBRARY_RELEASE "${PYTHON_LIBRARY}")
 include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
 SELECT_LIBRARY_CONFIGURATIONS(PYTHON)
+
+if(PYTHON_LIBRARY AND NOT PYTHON_LIBRARIES)
+  set(PYTHON_LIBRARIES "${PYTHON_LIBRARY}")
+endif()
 # SELECT_LIBRARY_CONFIGURATIONS() sets ${PREFIX}_FOUND if it has a library.
 # Unset this, this prefix doesn't match the module prefix, they are different
 # for historical reasons.