简体   繁体   中英

'ImportError: No module named ...' when trying to import pyx file to Jupyter

I have this file em.pyx in the same folder as the Jupyter notebook where I try to import it but it is giving me the error

ImportError: No module named em

I've tried adding

import sys
sys.path.insert(0, 'name_of_directory_where_pyxfile_is')

or

sys.path.append('my/path/to/module/folder')

as suggested here and here , but I keep getting the same error. I've also created an empy __init__.py file, but nothing.

EDIT: Then I added

import pyximport
pyximport.install()

before import em , and now I get lots of errors from python 2.7 (I don't know why python2 since the compilation of pyx was made with python3 and the jupyter kernel is also set to Python3); the first three are:

ImportError                               Traceback (most recent call     last)
<ipython-input-2-778b3d13b1ae> in <module>()
  2 pyximport.install()
  3 
----> 4 import em1d

/home/me/.local/lib/python2.7/site-packages/pyximport/pyximport.pyc in     load_module(self, fullname)
460                                  self.pyxbuild_dir,
461                                  build_inplace=self.inplace,
--> 462                                      language_level=self.language_level)
463         return module
464 

/home/me/.local/lib/python2.7/site-packages/pyximport/pyximport.pyc in     load_module(name, pyxfilename, pyxbuild_dir, is_package, build_inplace,     language_level, so_path)
231                 raise exc.with_traceback(tb)
232             else:
--> 233                 exec("raise exc, None, tb", {'exc': exc, 'tb': tb})
234     return mod
235 

EDIT2: Also, after running pyximport.install() I get (None, None)

这是一个简单的解决方案(在我看来)只需使用 cython 编译文件然后尝试

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