python + 导入C++编码帮助。缺失compiler_cxx修复MSVCCompiler;无法找到vcvarsall.bat

2 投票
1 回答
3256 浏览
提问于 2025-04-17 15:57

我安装了scipy和numpy。然后我又安装了MinGWCygwin。我把MinGW的路径加到了我的环境变量里。但是当我运行我的Python代码时,出现了这个错误信息。

*在numpy.distutils中找不到名为msvccompiler的模块;尝试从distutils中查找 缺少MSVCCompiler的compiler_cxx修复*

Traceback (most recent call last):
  File "C:\Python27\jicrd_simulation.py", line 633, in <module>
    cProfile.run('run()','infoprof_c_old')
  File "C:\Python27\lib\cProfile.py", line 29, in run
    prof = prof.run(statement)
  File "C:\Python27\lib\cProfile.py", line 135, in run
    return self.runctx(cmd, dict, dict)
  File "C:\Python27\lib\cProfile.py", line 140, in runctx
    exec cmd in globals, locals
  File "<string>", line 1, in <module>
  File "C:\Python27\jicrd_simulation.py", line 615, in run
    P,trace=search(g)
  File "C:\Python27\jicrd_simulation.py", line 580, in search
    hits=compute_hits(g,pos,P)
  File "C:\Python27\jicrd_simulation.py", line 299, in compute_hits
    source_counts = thetarange(g,g.source,move)
  File "C:\Python27\jicrd_simulation.py", line 229, in thetarange
    headers=['<stdio.h>','<stdlib.h>','<math.h>','"'+g.path +'/comp.h"'])
  File "C:\Python27\lib\site-packages\scipy\weave\inline_tools.py", line 355, in inline
    **kw)
  File "C:\Python27\lib\site-packages\scipy\weave\inline_tools.py", line 482, in compile_function
      verbose=verbose, **kw)
  File "C:\Python27\lib\site-packages\scipy\weave\ext_tools.py", line 367, in compile
      verbose = verbose, **kw)
    File "C:\Python27\lib\site-packages\scipy\weave\build_tools.py", line 272, in build_extension
      setup(name = module_name, ext_modules = [ext],verbose=verb)
    File "C:\Python27\lib\site-packages\numpy\distutils\core.py", line 186, in setup
      return old_setup(**new_attr)
    File "C:\Python27\lib\distutils\core.py", line 169, in setup
      raise SystemExit, "error: " + str(msg)
  CompileError: error: Unable to find vcvarsall.bat

那我现在该怎么办呢?我有一个MSVCCCompiler。

1 个回答

0

你在谈论C++编程,所以我猜你想要编译一个C/C++的扩展。为了在Win32上用MinGW编译我的C扩展,我是这样做的:

python setup.py build_ext --compiler mingw32

如果你想在Win64上编译,MinGW似乎不是最好的选择。我参考了这里这里的建议,最终用微软SDK中的VC++ 10成功编译了我的扩展。

撰写回答