[英]'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我有这个文件
em.pyx
与 Jupyter 笔记本在同一个文件夹中,我尝试导入它,但它给了我错误
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.我还创建了一个 empy
__init__.py
文件,但什么也没有。
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);在
import em
之前,现在我从 python 2.7 得到很多错误(我不知道为什么 python2 因为 pyx 的编译是用 python3 编译的,并且 jupyter 内核也设置为 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)
EDIT2:另外,在运行
pyximport.install()
我得到(None, None)
这是一个简单的解决方案(在我看来)只需使用 cython 编译文件然后尝试
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.