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.
On OSX:
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
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.
On Ubuntu:
sysconfig.get_config_var('INSTSONAME')
gives me the name of the library (libpython2.7.so.1.0).LIBDIR
returns only /usr/libCMake python modules: FindPythonLibs and FindPythonInterp.
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.
Example:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With