简体   繁体   English

为 cython 导入 numpy 时发生错误

[英]Error happens when import numpy for cython

When I use Cython in jupyter lab, an error happens.当我在 jupyter 实验室中使用 Cython 时,会发生错误。

%%cython
import numpy as np
cimport numpy as cnp

AttributeError Traceback (most recent call last) in ----> 1 get_ipython().run_cell_magic('cython', '', 'import numpy as np\ncimport numpy as cnp\n') ----> 1 get_ipython().run_cell_magic('cython', '', 'import numpy as np\ncimport numpy as cnp\n')

D:\professional\Anaconda_install\lib\site-packages\IPython\core\interactiveshell.py in run_cell_magic(self, magic_name, line, cell) 2360 D:\professional\Anaconda_install\lib\site-packages\IPython\core\interactiveshell.py in run_cell_magic(self, magic_name, line, cell) 2360
with self.builtin_trap: 2361 args = (magic_arg_s, cell) -> 2362 result = fn(*args, **kwargs) 2363 return result 2364 with self.builtin_trap: 2361 args = (magic_arg_s, cell) -> 2362 result = fn(*args, **kwargs) 2363 返回结果 2364

in cython(self, line, cell)在 cython(自我,线,细胞)

D:\professional\Anaconda_install\lib\site-packages\IPython\core\magic.py in (f, *a, **k) 185 # but it's overkill for just that one bit of state. D:\professional\Anaconda_install\lib\site-packages\IPython\core\magic.py in (f, *a, **k) 185 # 但对于 state 的那一点来说就有点过分了。 186 def magic_deco(arg): --> 187 call = lambda f, *a, **k: f(*a, **k) 188 189 if callable(arg): 186 def magic_deco(arg): --> 187 call = lambda f, *a, **k: f(*a, **k) 188 189 if callable(arg):

D:\professional\Anaconda_install\lib\site-packages\Cython\Build\IpythonMagic.py in cython(self, line, cell) 331 extension = None 332 if need_cythonize: --> 333 extensions = self._cythonize(module_name, code, lib_dir, args, quiet=args.quiet) 334 if extensions is None: 335 # Compilation failed and printed error message D:\professional\Anaconda_install\lib\site-packages\Cython\Build\IpythonMagic.py in cython(self, line, cell) 331 extension = None 332 if need_cythonize: --> 333 extensions = self._cythonize(module_name, code , lib_dir, args, quiet=args.quiet) 334 if extensions is None: 335 # 编译失败并打印错误信息

D:\professional\Anaconda_install\lib\site-packages\Cython\Build\IpythonMagic.py in _cythonize(self, module_name, code, lib_dir, args, quiet) 422 if 'numpy' in code: 423 import numpy --> 424 c_include_dirs.append(numpy.get_include()) 425 with io.open(pyx_file, 'w', encoding='utf-8') as f: 426 f.write(code) D:\professional\Anaconda_install\lib\site-packages\Cython\Build\IpythonMagic.py in _cythonize(self, module_name, code, lib_dir, args, quiet) 422 if 'numpy' in code: 423 import numpy --> 424 c_include_dirs.append(numpy.get_include()) 425 with io.open(pyx_file, 'w', encoding='utf-8') as f: 426 f.write(code)

AttributeError: module 'numpy' has no attribute 'get_include' AttributeError:模块“numpy”没有属性“get_include”

My numpy verison is 1.17.2 and there is no include folder in D:\professional\Anaconda_install\Lib\site-packages\numpy\core .我的 numpy 版本是 1.17.2 并且D:\professional\Anaconda_install\Lib\site-packages\numpy\core中没有include文件夹。 Does anyone know how to solve this problem?有谁知道如何解决这个问题? Thanks!谢谢!

Sorry to make a trouble.很抱歉给您添麻烦了。 I have just found that the numpy package crashes and the error has nothing to do with cython.我刚刚发现 numpy package 崩溃,错误与 cython 无关。 After uninstall and re-install numpy, the problem can be solved.卸载并重新安装numpy后,问题即可解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM