Skip to content

Commit

Permalink
Fix Python.h discovery logic on some MacOS platforms (#51586)
Browse files Browse the repository at this point in the history
Summary:
On all non-Windows platforms we should use 'posix_prefix' schema to discover location of Python.h header

Pull Request resolved: #51586

Reviewed By: ezyang

Differential Revision: D26208684

Pulled By: malfet

fbshipit-source-id: bafa6d79de42231629960c642d535f1fcf7a427f
  • Loading branch information
malfet authored and facebook-github-bot committed Feb 3, 2021
1 parent 7360ce3 commit f7313b3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions torch/utils/cpp_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -1720,8 +1720,12 @@ def _write_ninja_file_to_build_library(path,

# include_paths() gives us the location of torch/extension.h
system_includes = include_paths(with_cuda)
# sysconfig.get_paths()['include'] gives us the location of Python.h
system_includes.append(sysconfig.get_paths()['include'])
# sysconfig.get_path('include') gives us the location of Python.h
# Explicitly specify 'posix_prefix' scheme on non-Windows platforms to workaround error on some MacOS
# installations where default `get_path` points to non-existing `/Library/Python/M.m/include` folder
python_include_path = sysconfig.get_path('include', scheme='nt' if IS_WINDOWS else 'posix_prefix')
if python_include_path is not None:
system_includes.append(python_include_path)

# Windows does not understand `-isystem`.
if IS_WINDOWS:
Expand Down

0 comments on commit f7313b3

Please sign in to comment.