在使用cython编译最简单的helloworld程序时出现如下问题:
本人使用的是anaconda3+vs2015
Compiling helloworld.pyx because it changed.
[1/1] Cythonizing helloworld.pyx
running build_ext
Traceback (most recent call last):
File "setup.py", line 5, in <module>
ext_modules = cythonize("helloworld.pyx")
File "D:\anaconda\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "D:\anaconda\lib\distutils\dist.py", line 955, in run_commands
self.run_command(cmd)
File "D:\anaconda\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "D:\anaconda\lib\distutils\command\build_ext.py", line 308, in run
force=self.force)
File "D:\anaconda\lib\distutils\ccompiler.py", line 1031, in new_compiler
return klass(None, dry_run, force)
File "D:\anaconda\lib\distutils\cygwinccompiler.py", line 285, in __init__
CygwinCCompiler.__init__ (self, verbose, dry_run, force)
File "D:\anaconda\lib\distutils\cygwinccompiler.py", line 129, in __init__
if self.ld_version >= "2.10.90":
TypeError: '>=' not supported between instances of 'NoneType' and 'str'
helloworld.pyx文件中的代码
print('hello world')
setup.py中代码
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize("helloworld.pyx")
)
看了下代码中的注释:
self.gcc_version, self.ld_version, self.dllwrap_version = \
get_versions()
self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" %
(self.gcc_version,
self.ld_version,
self.dllwrap_version) )
# ld_version >= "2.10.90" and < "2.13" should also be able to use
# gcc -mdll instead of dllwrap
# Older dllwraps had own version numbers, newer ones use the
# same as the rest of binutils ( also ld )
# dllwrap 2.10.90 is buggy
if self.ld_version >= "2.10.90":
self.linker_dll = "gcc"
else:
self.linker_dll = "dllwrap"
感觉你应该最好用gcc来编译,而不是vc++,因为后者版本号的格式和这个判断不兼容。
或者你试试看修改cygwinccompiler.py文件,把这个判断注释下。
这个是什么问题造成的呢,大神帮忙解答一下
C:\MinGW\bin\gcc.exe -shared -s build\temp.win-amd64-3.6\Release\helloworld.o build\temp.win-amd64-3.6\Release\helloworld.cp36-win_amd64.def -LD:\anaconda\libs -LD:\anaconda\PCbuild\amd64 -lpython36 -lmsvcr140 -o "C:\Users\yangtianwei\Desktop\新建文件夹 (2)\helloworld.cp36-win_amd64.pyd"
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lmsvcr140
collect2.exe: 错误:ld 返回 1
error: command 'C:\\MinGW\\bin\\gcc.exe' failed with exit status 1
1.最后一行不是提示'>=' not supported between instances of 'NoneType' and 'str'
可能是你一个返回空的函数在和字符串作比较
2.cannot find -lmsvcr140 初步怀疑你可能缺少msvcr140.dll之类的可以网上下载,名字不一定正确,反正差不多
我装在D盘,然后将这个放在用户环境变量里,还是报错