未验证 提交 97112dde 编写于 作者: H HongyuJia 提交者: GitHub

[Custom Op] Add Python.h include dir path automatically (#51567)

* [Custom Op] Add Python.h include dir path automatically

* add debug info

* fix expand str error
上级 2d97316f
......@@ -23,6 +23,7 @@ import os
import re
import subprocess
import sys
import sysconfig
import textwrap
import threading
import warnings
......@@ -543,6 +544,7 @@ def normalize_extension_kwargs(kwargs, use_cuda=False):
include_dirs = list(kwargs.get('include_dirs', []))
include_dirs.extend(compile_include_dirs)
include_dirs.extend(find_paddle_includes(use_cuda))
include_dirs.extend(find_python_includes())
kwargs['include_dirs'] = include_dirs
......@@ -785,6 +787,22 @@ def find_paddle_includes(use_cuda=False):
return include_dirs
def find_python_includes():
"""
Return necessary include dir path of Python.h.
"""
# 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:
assert isinstance(python_include_path, str)
return [python_include_path]
return []
def find_clang_cpp_include(compiler='clang'):
std_v1_includes = None
try:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册