Cython模板化类错误

时间:2017-01-08 09:35:39

标签: python c++ cython

当我尝试在jupyter笔记本中运行以下代码时出现错误。 代码来自http://cython.readthedocs.io/en/latest/src/userguide/wrapping_CPlusPlus.html

的教程
  %%cython
    from libcpp.vector cimport vector

    cdef vector[int] vect
    cdef int i
    for i in range(10):
        vect.push_back(i)
    for i in range(10):
        print vect[i]

这是与microsoft visual studio有关的错误

 DistutilsExecError                        Traceback (most recent call last)
    C:\Users\aalha\Anaconda3\lib\distutils\_msvccompiler.py in compile(self, sources, output_dir, macros, include_dirs, debug, extra_preargs, extra_postargs, depends)
        383             try:
    --> 384                 self.spawn(args)
        385             except DistutilsExecError as msg:

    C:\Users\aalha\Anaconda3\lib\distutils\_msvccompiler.py in spawn(self, cmd)
        502             os.environ['path'] = self._paths
    --> 503             return super().spawn(cmd)
        504         finally:

    C:\Users\aalha\Anaconda3\lib\distutils\ccompiler.py in spawn(self, cmd)
        908     def spawn(self, cmd):
    --> 909         spawn(cmd, dry_run=self.dry_run)
        910 

    C:\Users\aalha\Anaconda3\lib\distutils\spawn.py in spawn(cmd, search_path, verbose, dry_run)
         37     elif os.name == 'nt':
    ---> 38         _spawn_nt(cmd, search_path, dry_run=dry_run)
         39     else:

    C:\Users\aalha\Anaconda3\lib\distutils\spawn.py in _spawn_nt(cmd, search_path, verbose, dry_run)
         80             raise DistutilsExecError(
    ---> 81                   "command %r failed with exit status %d" % (cmd, rc))
         82 

    DistutilsExecError: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

    During handling of the above exception, another exception occurred:

    CompileError                              Traceback (most recent call last)
    <ipython-input-274-411422239836> in <module>()
    ----> 1 get_ipython().run_cell_magic('cython', '', 'from libcpp.vector cimport vector\n\ncdef vector[int] vect\ncdef int i\nfor i in range(10):\n    vect.push_back(i)\nfor i in range(10):\n    print vect[i]')

    C:\Users\aalha\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py in run_cell_magic(self, magic_name, line, cell)
       2113             magic_arg_s = self.var_expand(line, stack_depth)
       2114             with self.builtin_trap:
    -> 2115                 result = fn(magic_arg_s, cell)
       2116             return result
       2117 

    <decorator-gen-125> in cython(self, line, cell)

    C:\Users\aalha\Anaconda3\lib\site-packages\IPython\core\magic.py in <lambda>(f, *a, **k)
        186     # but it's overkill for just that one bit of state.
        187     def magic_deco(arg):
    --> 188         call = lambda f, *a, **k: f(*a, **k)
        189 
        190         if callable(arg):

    C:\Users\aalha\Anaconda3\lib\site-packages\Cython\Build\IpythonMagic.py in cython(self, line, cell)
        282             build_extension.build_temp = os.path.dirname(pyx_file)
        283             build_extension.build_lib  = lib_dir
    --> 284             build_extension.run()
        285             self._code_cache[key] = module_name
        286 

    C:\Users\aalha\Anaconda3\lib\distutils\command\build_ext.py in run(self)
        336 
        337         # Now actually compile and link everything.
    --> 338         self.build_extensions()
        339 
        340     def check_extensions_list(self, extensions):

    C:\Users\aalha\Anaconda3\lib\distutils\command\build_ext.py in build_extensions(self)
        445             self._build_extensions_parallel()
        446         else:
    --> 447             self._build_extensions_serial()
        448 
        449     def _build_extensions_parallel(self):

    C:\Users\aalha\Anaconda3\lib\distutils\command\build_ext.py in _build_extensions_serial(self)
        470         for ext in self.extensions:
        471             with self._filter_build_errors(ext):
    --> 472                 self.build_extension(ext)
        473 
        474     @contextlib.contextmanager

    C:\Users\aalha\Anaconda3\lib\distutils\command\build_ext.py in build_extension(self, ext)
        530                                          debug=self.debug,
        531                                          extra_postargs=extra_args,
    --> 532                                          depends=ext.depends)
        533 
        534         # XXX outdated variable, kept here in case third-part code

    C:\Users\aalha\Anaconda3\lib\distutils\_msvccompiler.py in compile(self, sources, output_dir, macros, include_dirs, debug, extra_preargs, extra_postargs, depends)
        384                 self.spawn(args)
        385             except DistutilsExecError as msg:
    --> 386                 raise CompileError(msg)
        387 
        388         return objects

    CompileError: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

0 个答案:

没有答案