源码为linux系统的,在windows运行出现问题,找不到相关文件 bbox,查看
发现是由cython编写的,生成的文件为.so格式,在windows下自然用不了。
修改setup文件,生成windows文件.pyd。
1 | #原文件 |
直接运行1
python .\setup_cpu.py build_ext --inplace
出现错误1
2
3File "setup_cpu.py", line 50, in customize_compiler_for_nvcc
default_compiler_so = self.compiler_so
AttributeError: 'MSVCCompiler' object has no attribute 'compiler_so'
这里自定义的编译器为linux的gcc,需要修改1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50from Cython.Build import cythonize
import os
from os.path import join as pjoin
import numpy as np
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
def find_in_path(name, path):
for dir in path.split(os.pathsep):
binpath = pjoin(dir, name)
if os.path.exists(binpath):
return os.path.abspath(binpath)
return None
try:
numpy_include = np.get_include()
except AttributeError:
numpy_include = np.get_numpy_include()
# run the customize_compiler
class custom_build_ext(build_ext):
def build_extensions(self):
self.compiler.src_extensions.append('.cu')
self.compiler.set_executable('compiler_so', 'nvcc')
self.compiler.set_executable('linker_so', 'nvcc --shared')
if hasattr(self.compiler, '_c_extensions'):
self.compiler._c_extensions.append('.cu') # needed for Windows
self.compiler.spawn = self.spawn
build_ext.build_extensions(self)
ext_modules = [
Extension(
"utils.bbox",
["bbox.pyx"],
extra_compile_args=['-Wno-cpp', '-Wno-unused-function', '-std=c99'],
include_dirs = [numpy_include]
),
Extension(
"utils.cython_nms",
["cython_nms.pyx"],
extra_compile_args=['-Wno-cpp', '-Wno-unused-function', '-std=c99'],
include_dirs = [numpy_include]
),]
setup(
ext_modules=ext_modules,
cmdclass={'build_ext': custom_build_ext},
)
运行生成build和utile文件夹,将utile中的.pyd文件拷贝出来,删除两个文件夹