在Jupyter中,我自己的小模块没有加载,但在python/bpython中,一切都很好。当键入时
import sys
print(sys.path)
我的模块的路径在Jupyter中不会显示,但在python/bpython中它仍然存在。
我正在使用:
.bashrc中的
最相似的问题是这个Cannot import modules in jupyter notebook; wrong sys.path
如何配置Jupyter自动加载我的模块?
发布于 2017-03-11 04:53:23
这是我在jupyter笔记本上做的项目,
import sys
sys.path.append("../") # go to parent dir
from customFunctions import *
然后,为了影响customFunctions.py
中的更改,
%load_ext autoreload
%autoreload 2
发布于 2018-05-12 19:20:11
Jupyter是基于ipython的,一个永久的解决方案是改变ipython的配置选项。
创建配置文件
$ ipython profile create
$ ipython locate
/Users/username/.ipython
编辑配置文件
$ cd /Users/username/.ipython
$ vi profile_default/ipython_config.py
以下几行允许您将模块路径添加到sys.path
c.InteractiveShellApp.exec_lines = [
'import sys; sys.path.append("/path/to/your/module")'
]
在jupyter启动时,将执行前一行
您可以在此处找到有关ipython配置https://www.lucypark.kr/blog/2013/02/10/when-python-imports-and-ipython-does-not/的更多详细信息
发布于 2017-09-12 23:13:43
Jupyter有自己的PATH变量JUPYTER_PATH。
将这一行添加到.bashrc
文件中对我很有效:
export JUPYTER_PATH=<directory_for_your_module>:$JUPYTER_PATH
https://stackoverflow.com/questions/34976803
复制相似问题