问题描述
- AttributeError: ‘MSVCCompiler’ object has no attribute ‘compiler_so’
- ValueError: Buffer dtype mismatch, expected ‘int_t’ but got 'long long
- ImportError: cannot import name ‘bbox’
- mv: 无法获取’utils/*’ 的文件状态(stat): No such file or directory
-
Cython fatal error C1083: 无法打开包括文件: “numpy/arrayobject.h”: No such file or directory
问题分析
这些文件在 Fast-RCNN 项目(https://github.com/rbgirshick/fast-rcnn/tree/master/lib/utils)已经被使用,而yolo、ctpn等目标检测框架继承或者使用了 Fast-RCNN 项目,导致出现都出现编译问题。
faster-rcnn、yolo、ctpn等目标检测框架均在Linux环境下开发,似乎没有考虑Windows的兼容性问题。
1.这个问题在win7上无解,无论怎么安装vs2015还是.net什么都没用,Windows10上是可以的,亲测有效;
2.np.int_t在Windows和Linux中可能大小并不相同(issues:https://github.com/eragonruan/text-detection-ctpn/issues/380)(针对第二个问题)
3.这个是纯编译问题,Windows7上貌似没办法编译。
4.编译完成会生成一个.so文件(Linux下的.so文件是基于Linux下的动态链接库),但是这个文件没法复制,在Windows上也无法使用,这也是为什么需要手动编译的原因。(针对第三个问题)
5.mv是Linux系统移动文件的指令(可参阅:https://www.runoob.com/linux/linux-comm-mv.html),所以这个问题Linux不会发生。(这个问题出现在make.sh文件中)(针对第四个问题)
6..compiler_so
字段仅存在于distutils.unixcompiler.UnixCCompiler
和派生中。因此,此程序包不支持标准的Windows构建环境。根据Windows上的“从源构建” | TensorFlow,应该使用MSYS2构建。(针对第一个问题)
Cython——[AttributeError: ‘MSVCCompiler‘ object has no attribute ‘compiler_so‘]解决方案
7.在Cython编译成c时,如果使用python库,需要包含相应的python库(针对第五个问题)
解决方案
一般方案
1. 针对make.sh文件的问题
可以修改成make.bat文件以支持Windows10
cython bbox.pyx
cython cython_nms.pyx
cython gpu_nms.pyx
python setup.py install
copy utils/* ./
del /s build
del /s utils
python setup.py build
python setup.py install
2.针对【AttributeError: ‘MSVCCompiler’ object has no attribute ‘compiler_so’】问题
Cython——[AttributeError: ‘MSVCCompiler‘ object has no attribute ‘compiler_so‘]解决方案
3.针对.so或者.pyd文件模型里import的代码名称不同问题
事实上,这并不需要重命名,只要将文件移动到对应位置(即/lib/utils/)即可。
4.针对【Cython fatal error C1083: 无法打开包括文件: “numpy/arrayobject.h”: No such file or directory】问题
添加 include_dirs=[np.get_include()]
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import numpy as np
setup(
cmdclass={'build_ext': build_ext},
ext_modules=[Extension('calculate', ['cythonfnS.pyx'])],
include_dirs=[np.get_include()])
5.针对【ValueError: Buffer dtype mismatch, expected 'int_t' but got 'long long'】问题
issues:https://github.com/eragonruan/text-detection-ctpn/issues/380
将第25行或者第27行cython_nms.pyx中的np.int_t Replace >> np.int64_t
NOTICE: After makeing this change. You need to compile setup.py again
懒人方案
已经编译完成的文件(搬运)(缺少bbox.pyd)
参考文章
win配置faster-rcnn、yolo、ctpn等目标检测的几个大坑
Cython——[AttributeError: ‘MSVCCompiler‘ object has no attribute ‘compiler_so‘]解决方案