问题描述
是否有任何独立于平台的方式来获取python安装的libpython的路径(用作cmake参数)? sysconfig.get_config_var
给出了一些内容,但是没有一致的方法可以使它正常工作。
Is there any platform independent way to get the path to a python installation's libpython, for use as a cmake argument? sysconfig.get_config_var
gives some pieces but there's no consistent way I can get this working.
在OSX上:
- 没有变量包含库的实际基本名称(libpython2.7.dylib)
-
sysconfig.get_config_var('LIBDIR')
返回目录libpython2.7.dylib在(/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib)中 -
编辑:似乎在sysconfig报告符号链接和报告真实路径时存在一些差异。
LIBDIR
实际上确实包含libpython.2.7.dylib,但是我刚刚注意到的是这是/usr/local/Cellar/python/2.7.13_1/Frameworks的符号链接/Python.framework/Versions/2.7/Python。
- No variable contains the actual basename of the library (libpython2.7.dylib)
sysconfig.get_config_var('LIBDIR')
returns the directory libpython2.7.dylib is in (/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib)edit: There seems to be a bit of a discrepancy in when sysconfig is reporting a symlink and when it's reporting a real path.
LIBDIR
does in fact contain libpython.2.7.dylib, but what I just noticed is that this is a symlink to /usr/local/Cellar/python/2.7.13_1/Frameworks/Python.framework/Versions/2.7/Python.
INSTSONAME
指向Python.framework / Versions / 2.7 / Python,该路径的基本名称,但我找不到指向该路径父级部分的变量。
INSTSONAME
points to Python.framework/Versions/2.7/Python, the basename of that path, but no variable I can find points to the parent part of that path.
在Ubuntu上:
-
sysconfig.get_config_var('INSTSONAME')
给我起名字库(libpython2.7.so.1.0)。 - 没有变量包含它所在的目录(/ usr / lib / x86_64-linux-gnu /)。
-
LIBDIR
仅返回/ usr / lib
sysconfig.get_config_var('INSTSONAME')
gives me the name of the library (libpython2.7.so.1.0).- No variable contains the directory it's in (/usr/lib/x86_64-linux-gnu/).
LIBDIR
returns only /usr/lib
推荐答案
CMake python模块:和。
CMake python modules: FindPythonLibs and FindPythonInterp.
如果这些方法对您不起作用,只需在调用cmake <$时设置下一个变量c $ c> -DPYTHON_EXECUTABLE:FILEPATH ,
-DPYTHON_LIBRARY:FILEPATH
和-DPYTHON_INCLUDE_DIR:FILEPAT
,有关更多信息,请在。If those don't work for you just set the next vars when calling cmake
-DPYTHON_EXECUTABLE:FILEPATH
,-DPYTHON_LIBRARY:FILEPATH
and-DPYTHON_INCLUDE_DIR:FILEPAT
, for more info look here.示例:
cmake .. -G "Sublime Text 2 - Ninja" -DCMAKE_BUILD_TYPE=Release -DPYTHON_EXECUTABLE:FILEPATH=d:\virtualenvs\python362_32 -DPYTHON_LIBRARY:FILEPATH=d:\virtualenvs\python362_32\libs\python36.lib -DPYTHON_INCLUDE_DIR:FILEPAT=d:\virtualenvs\python362_32\include
这篇关于平台无关的方法来找到libpython的路径(例如,用于cmake)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
-