Caffe2 - Python API
A deep learning, cross platform ML framework
get_python_cmake_flags.py
1 ## @package get_python_cmake_flags
2 # Module scripts.get_python_cmake_flags
3 ##############################################################################
4 # Use this script to find your preferred python installation.
5 ##############################################################################
6 #
7 # You can use the following to build with your preferred version of python
8 # if your installation is not being properly detected by CMake.
9 #
10 # mkdir -p build && cd build
11 # cmake $(python ../scripts/get_python_libs.py) ..
12 # make
13 #
14 
15 from __future__ import absolute_import
16 from __future__ import unicode_literals
17 from __future__ import print_function
18 from distutils import sysconfig
19 import os
20 import sys
21 import platform
22 
23 # Flags to print to stdout
24 flags = ''
25 inc = sysconfig.get_python_inc()
26 lib = sysconfig.get_config_var("LIBDIR")
27 
28 # macOS specific
29 if sys.platform == "darwin":
30  lib = os.path.dirname(lib) + '/Python'
31  if os.path.isfile(lib):
32  flags += '-DPYTHON_LIBRARY={lib} '.format(lib=lib)
33 
34 if os.path.isfile(inc + '/Python.h'):
35  flags += '-DPYTHON_INCLUDE_DIR={inc} '.format(inc=inc)
36 
37 print(flags, end='')