Properly set cmake python library and include_dirs (#12569)

Summary:
Properly set cmake python_library and include_dirs hints, so that systems with multiple version of python can still find the correct libraries and header files.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/12569

Differential Revision: D10359910

Pulled By: soumith

fbshipit-source-id: 2238dcbed7aac8a818c9435e6bba46cda5f81cad
This commit is contained in:
Philip Yang
2018-10-12 08:06:43 -07:00
committed by Facebook Github Bot
parent 48bc57fa8d
commit b57fdf1db5
2 changed files with 9 additions and 0 deletions

View File

@ -224,6 +224,11 @@ caffe2_build_dir = os.path.join(cwd, "build")
rel_site_packages = distutils.sysconfig.get_python_lib(prefix='')
# full absolute path to the dir above
full_site_packages = distutils.sysconfig.get_python_lib()
# CMAKE: full path to python library
cmake_python_library = "{}/{}".format(
distutils.sysconfig.get_config_var("LIBDIR"),
distutils.sysconfig.get_config_var("INSTSONAME"))
cmake_python_include_dir = distutils.sysconfig.get_python_inc()
class PytorchCommand(setuptools.Command):
@ -352,6 +357,8 @@ def build_libs(libs):
build_libs_cmd = ['bash', os.path.join('..', 'tools', 'build_pytorch_libs.sh')]
my_env = os.environ.copy()
my_env["PYTORCH_PYTHON"] = sys.executable
my_env["PYTORCH_PYTHON_LIBRARY"] = cmake_python_library
my_env["PYTORCH_PYTHON_INCLUDE_DIR"] = cmake_python_include_dir
my_env["PYTORCH_BUILD_VERSION"] = version
my_env["CMAKE_PREFIX_PATH"] = full_site_packages
my_env["NUM_JOBS"] = str(NUM_JOBS)