简体   繁体   中英

Error happens when import numpy for cython

When I use Cython in jupyter lab, an error happens.

%%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')

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

in cython(self, line, cell)

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. 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 _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'

My numpy verison is 1.17.2 and there is no include folder in D:\professional\Anaconda_install\Lib\site-packages\numpy\core . 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. After uninstall and re-install numpy, the problem can be solved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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