简体   繁体   中英

OS X cmake can't find PythonLibs 3.4

python and python3 are installed in OS X Yosemite via Homebrew, but cmake fails to find PythonLibs 3, only 2:


CMakeLists.txt:

set(Python_ADDITIONAL_VERSIONS 3.4)
FIND_PACKAGE(PythonInterp REQUIRED)
FIND_PACKAGE(PythonLibs 3.4 REQUIRED)

get:

-- Found PythonInterp: /usr/local/bin/python3.4 (found suitable version "3.4.3", minimum required is "3.4")
-- Found PythonLibs: /usr/lib/libpython3.4.dylib (found version "2.7.6"

CMakeLists.txt:

set(Python_ADDITIONAL_VERSIONS 3.4)
FIND_PACKAGE(PythonInterp 3.4 REQUIRED)
FIND_PACKAGE(PythonLibs 3.4 REQUIRED)

get:

Could NOT find PythonLibs: Found unsuitable version "2.7.6", but required
is at least "3.4" (found PYTHON_LIBRARY-NOTFOUND)


Then I added this to cmake lists:

INCLUDE_DIRECTORIES(/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib)
INCLUDE_DIRECTORIES(/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/include/python3.4m)

and even copied that directories to /usr/lib , and then got:

Could NOT find PythonLibs: Found unsuitable version "2.7.6", but required
is at least "3.4" (found /usr/lib/libpython3.4.dylib)

that looks weird.

It appears the correct version of Python is found in your CMake configuration, but locations of the libraries also needs to be set. Depending on your installation/configuration the location of the libraries might vary, although in the configuration you'll want something similar:

PYTHON_LIBRARIES=/Library/Frameworks/Python.framework/Versions/3.4/lib/libpython3.4m.dylib
PYTHON_INCLUDE_DIR=/Library/Frameworks/Python.framework/Versions/3.4/include/python3.4m

http://www.cmake.org/cmake/help/v3.0/module/FindPythonLibs.html

You need to add the path to the libraries in your "LD_LIBRARY_PATH" environment variable. In this way, CMake will know where to look for them. This may happen with multiple python installations or when it is installed in a non standard location. This should solve it:

export LD_LIBRARY_PATH=/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib:$LD_LIBRARY_PATH

The CMake command "INCLUDE_DIRECTORIES" is only for headers (aka. /usr/include).

-> If my solution doesn't work, make sure you have python-devel installed: how to install python-devel in Mac OS?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM