Cython——[AttributeError: ‘MSVCCompiler‘ object has no attribute ‘compiler_so‘]解决方案

问题描述

运行环境

Windows 10

Python3.7

TensorFlow 1.3.0

GitHub文件URL:https://github.com/xiaofengShi/CHINESE-OCR/blob/master/ctpn/lib/utils/setup.py

python setup.py build_ext --inplace
running build_ext
Traceback (most recent call last):
  File "setup.py", line 150, in <module>
    cmdclass={'build_ext': custom_build_ext},
  File "C:\Users\USER\AppData\Local\Programs\Python\Python35\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "C:\Users\USER\AppData\Local\Programs\Python\Python35\lib\distutils\dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "C:\Users\USER\AppData\Local\Programs\Python\Python35\lib\distutils\dist.py", line 974, in run_command
    cmd_obj.run()
  File "C:\Users\USER\AppData\Local\Programs\Python\Python35\lib\site-packages\Cython\Distutils\old_build_ext.py", line 186, in run
    _build_ext.build_ext.run(self)
  File "C:\Users\USER\AppData\Local\Programs\Python\Python35\lib\distutils\command\build_ext.py", line 338, in run
    self.build_extensions()
  File "setup.py", line 104, in build_extensions
    customize_compiler_for_nvcc(self.compiler)
  File "setup.py", line 77, in customize_compiler_for_nvcc
    default_compiler_so = self.compiler_so
AttributeError: 'MSVCCompiler' object has no attribute 'compiler_so'

问题分析

因此,此程序包不支持标准的Windows构建环境。

根据Windows上的“从源构建” | TensorFlow,应该使用MSYS2构建。

解决方案

方法一

删除所有自定义配置,采取默认方式。

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
 
setup(
  name = 'hellocython',
  ext_modules=cythonize([
    Extension("hellocython", ["hellocython.pyx"]),
    ]),
)
python setup.py build
python setup.py install

 方法二

使用MinGW64编译器:https://www.jianshu.com/p/50105307dea5

参考文章

AttributeError: 'MSVCCompiler' object has no attribute 'compiler_so'

【Cython】Cython在Windows环境下的部署安装

cython: 使用mingw编译器

win配置faster-rcnn、yolo、ctpn等目标检测的几个大坑

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 1024 设计师:白松林 返回首页