Pythonlibs3 CMake和macOS [英] Pythonlibs3 CMake and macOS

查看:284
本文介绍了Pythonlibs3 CMake和macOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[更新2]

以下两行添加到我的CMake文件中后,成功找到了python 3及其库.之所以只能在终端中使用,是因为CLion使用的是捆绑版本的CMake(3.6.3),而我的终端正在使用的更新版本(3.7.2)可以正确找到python.

The following two lines, when added to my CMake file, successfully found python 3 and its libraries. The reason this was only working in the terminal was because CLion was using its bundled version of CMake (3.6.3) and the updated version my terminal was using (3.7.2) correctly finds python.

FIND_PACKAGE(PythonInterp 3)
FIND_PACKAGE(PythonLibs 3)

[更新]我得到了cmake文件,但是,当我从终端运行时,它仅找到python3库.从CLion运行时,出现以下错误:

[UPDATE] I got the cmake file to work, however, it only finds the python3 library when I run from the terminal. When running from CLion, I get the following error:

CMake错误:此项目中使用了以下变量,但 它们设置为NOTFOUND.请设置它们或确保已设置它们 并在CMake文件中正确测试:PYTHON_LIBRARY(ADVANCED)

CMake Error: The following variables are used in this project, but they are set to NOTFOUND. Please set them or make sure they are set and tested correctly in the CMake files: PYTHON_LIBRARY (ADVANCED)

[原始帖子]

我正在开发一个跨平台的C ++应用程序,并将PythonLibs 3与boost_python一起使用,以便能够从python调用c ++方法.在ubuntu上,这工作正常,但是在macOS上,我似乎无法使cmake识别pythonlibs3.

I am developing a cross platform C++ application and using PythonLibs 3 along with boost_python to be able to call c++ methods from python. On ubuntu this is working fine however, on macOS, I can't seem to get cmake to recognize pythonlibs3.

在ubuntu上,以下行有效:

On ubuntu the following line works:

FIND_PACKAGE(PythonLibs 3 REQUIRED)

但是,在macOS上,它只能在/usr/libs/

However, on macOS, it can only fine pythonlibs 2.7.10 in /usr/libs/

我尝试了以下操作:

  1. 使用python3虚拟环境,然后运行cmake.
  2. set(Python_ADDITIONAL_VERSIONS 3.6)添加到我的cmake
  1. Using a python3 virtual environment and then running cmake.
  2. adding set(Python_ADDITIONAL_VERSIONS 3.6) to my cmake

其他信息:

  • 我在brew上安装了python3(3.6),它位于/usr/local/bin
  • 我正在使用cmake版本3.6.3
  • 当我写FIND_PACKAGE(PythonInterp 3)时,cmake可以找到我的python3安装.
  • 当检查我的/usr/lib/文件夹时,我发现了libpython2.7.dylib,但是在/usr/lib//usr/local/lib/中都没有libpython3.6/dylib.这似乎是因为此文件位于/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib.
  • I installed python3 (3.6) with brew, and it is located in /usr/local/bin
  • I am using cmake version 3.6.3
  • When I write FIND_PACKAGE(PythonInterp 3) cmake is able to find my python3 installation.
  • When checking my /usr/lib/ folder, I found libpython2.7.dylib but I do not have a libpython3.6/dylib in either /usr/lib/ or /usr/local/lib/. This seems to be because this file is located /usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib.

如果我将libpython3.6的位置添加到我的find_package中,

If I add the location of libpython3.6 to my find_package,

FIND_PACKAGE(PythonLibs 3 PATHS /usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/ REQUIRED)

它能够找到该库,但随后出现错误:

it is able to find the library but then I get the error:

找不到"PythonLibs"提供的软件包配置文件.
(要求版本3),具有以下任何名称:

Could not find a package configuration file provided by "PythonLibs"
(requested version 3) with any of the following names:

PythonLibsConfig.cmake
pythonlibs-config.cmake

将"PythonLibs"的安装前缀添加到CMAKE_PREFIX_PATH或 将"PythonLibs_DIR"设置为包含上述内容之一的目录 文件.如果"PythonLibs"提供了单独的开发包,或者 SDK,请确保已安装.

Add the installation prefix of "PythonLibs" to CMAKE_PREFIX_PATH or set "PythonLibs_DIR" to a directory containing one of the above files. If "PythonLibs" provides a separate development package or SDK, be sure it has been installed.

此外,如果我尝试在不使用find_package的情况下设置python变量,则可以找到该库:

Additionally, if I try to set the python variables without using find_package, it is able to find the library:

SET(PYTHON_INCLUDE_PATH /usr/local/include/python3.6mu) SET(PYTHON_EXECUTABLE /usr/local/bin/python3.6mu) SET(PYTHON_INCLUDE_DIR /usr/local/include/python3.6mu) SET(PYTHON_LIBRARIES /usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/)

SET(PYTHON_INCLUDE_PATH /usr/local/include/python3.6mu) SET(PYTHON_EXECUTABLE /usr/local/bin/python3.6mu) SET(PYTHON_INCLUDE_DIR /usr/local/include/python3.6mu) SET(PYTHON_LIBRARIES /usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/)

但是稍后在我的cmake中,我在以下行上收到错误消息:

but later on in my cmake I get an error on the following line:

PYTHON_ADD_MODULE(${PYRITMO_LIB} src/pythonwrappers.cpp)

该错误显示为:

未知的CMake命令"PYTHON_ADD_MODULE".

Unknown CMake command "PYTHON_ADD_MODULE".

出现这种情况的原因似乎是因为FindPythonLibs.cmake提供了此功能,而find_package(Pythonlibs)加载了该​​功能,因此,如果不使用它来定位PythonLib,则无法调用此功能.

The reason for this appears to be because this function is provided by FindPythonLibs.cmake which is loaded in by find_package(Pythonlibs) and therefore, if this is not used to located PythonLibs, this function cannot be called.

推荐答案

如问题更新中所述,转到CMake 3.7.2并使用以下两行内容解决了我的问题:

As stated above in the update to the question, moving to CMake 3.7.2 and using the following two lines fixed my issues:

FIND_PACKAGE(PythonInterp 3)
FIND_PACKAGE(PythonLibs 3)

[更新]对于使用Google Test并通过CMake安装它的任何人,将以上几行放在Google Test代码之前是很重要的.这是因为Google测试将查找python,然后找到python2,然后,当这两行运行时,它们将无法找到python3.

[UPDATE] For anyone using Google Test and installing it via CMake, it is important to put the above lines before the Google Test code. This is because Google test will look for python, and find python2, then when these two lines are run, they will not be able to find python 3.

如果这两行放在Google Test安装代码之前,则会找到python3并用于Google test.

If these two lines are placed before the Google Test install code, then python3 will be found and used for google test.

这篇关于Pythonlibs3 CMake和macOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆