如何解决使用setuptools从pytorch的cpp扩展名获取python文件失败的问题?

2024-05-16 10:51:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我想尝试一个名为deformable kernels的github项目,并按照README.md文件中描述的步骤进行操作:

conda env create -f environment.yml
 
cd deformable_kernels/ops/deform_kernel;
pip install -e .;

deformable_kernel/ops/deform_kernel的结构如下所示:

.
csrc
    filter_sample_depthwise_cuda.cpp
    filter_sample_depthwise_cuda.h
    filter_sample_depthwise_cuda_kernel.cu
    nd_linear_sample_cuda.cpp
    nd_linear_sample_cuda.h
    nd_linear_sample_cuda_kernel.cu
functions
    filter_sample_depthwise.py
    __init__.py
    nd_linear_sample.py
__init__.py
modules
    filter_sample_depthwise.py
    __init__.py
setup.py

文件setup.py的内容如下所示:

from setuptools import setup
from torch.utils.cpp_extension import BuildExtension, CUDAExtension
 
setup(
    name='filter_sample_depthwise',
    ext_modules=[
        CUDAExtension(
            'filter_sample_depthwise_cuda',
            [
                'csrc/filter_sample_depthwise_cuda.cpp',
                'csrc/filter_sample_depthwise_cuda_kernel.cu',
            ]
        ),
    ],
    cmdclass={'build_ext': BuildExtension}
)
 
setup(
    name="nd_linear_sample",
    ext_modules=[
        CUDAExtension(
            "nd_linear_sample_cuda",
            [
                "csrc/nd_linear_sample_cuda.cpp",
                "csrc/nd_linear_sample_cuda_kernel.cu",
            ],
        )
    ],
    cmdclass={"build_ext": BuildExtension},
)

当我使用命令pip install -e .安装此目录时,它失败了,结果是:

Obtaining file:///home/xxx/Downloads/deformable_kernels/deformable_kernels/ops/deform_kernel
ERROR: More than one .egg-info directory found in /tmp/pip-pip-egg-info-pta6z__q

因此,我尝试在不同的setup.py文件中分离2setup()。它工作了,但我没有得到python文件。而是生成了一个.so文件

有人知道如何解决这样的问题吗


Tags: pip文件samplepysetupfilterkernelcpp
1条回答
网友
1楼 · 发布于 2024-05-16 10:51:45

检查您的pip版本。我也犯过同样的错误(当用pip在开发模式下安装其他东西时),并且降级到pip版本20.0.2是有效的。不知道为什么,但我在互联网上看到其他人也用同样的方法解决了这个问题

相关问题 更多 >