我正在用C++编写一个python扩展,使用pybind11,我正在尝试创建setup.py
文件,这是我目前为止所做的:
from glob import glob
import setuptools
from pybind11.setup_helpers import Pybind11Extension, build_ext
ext_modules = [
Pybind11Extension(
"my_ext",
sorted(glob("src/my_ext/**/*.cc")),
)
]
setuptools.setup(
name="my_ext",
version="0.1",
package_dir={"": "src/my_ext/python/"},
cmdclass={"build_ext": build_ext},
ext_modules=ext_modules,
)
但是,当我运行pip install .
时,我得到了这个错误:
In file included from src/my_ext/cc/thing.cc:7:
src/my_ext/cc/thing.h:9:10: fatal error: 'torch/torch.h' file not found
#include <torch/torch.h>
^~~~~~~~~~~~~~~
1 error generated.
error: command '/usr/bin/clang' failed with exit code 1
有没有什么参数可以传递给Pybind11Extension,让它找到torch并成功构建?
1条答案
按热度按时间dwthyt8l1#
我自己想出来的。只需要使用一些pytorch的helper函数,并查看
torch.utils.cpp_extension.CppExtension
以获得指导: