python - Jupyter 和 Python 中的 sys.path 不同 - 如何在 Jupyter 中导入自己的模块?

标签 python jupyter pythonpath

在 Jupyter 中我自己的小模块没有加载,但在 python/bpython 中一切都很好。打字时

import sys
print(sys.path)

我的模块的路径不会在 Jupyter 中显示,但在 python/bpython 中它仍然存在。

我正在使用:

  1. .bashrc 中的 PYTHONPATH 以包含我的模块,
  2. 虚拟环境中的 Jupyter 和 bpython。

最相似的问题是这个 Cannot import modules in jupyter notebook; wrong sys.path

如何配置 Jupyter 以自动加载我的模块?

最佳答案

这是我在 jupyter notebook 中的项目所做的,

import sys
sys.path.append("../") # go to parent dir
from customFunctions import *

然后,要影响 customFunctions.py 中的更改,

%load_ext autoreload
%autoreload 2

关于python - Jupyter 和 Python 中的 sys.path 不同 - 如何在 Jupyter 中导入自己的模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34976803/

相关文章:

python - 计算列表中字母表的出现次数

python - 无法连接到 Kubernetes 上的 PyMongo DB

python - jupyter notebook --NotebookApp.iopub_data_rate_limit=10000000 不工作

pycharm - Jupyter Notebook 不与 PyCharm 同步

python - 如何将变量文件路径传递给位于 PYTHONPATH 上的 Robot Framework?

python - 使用 __init__.py 修改 sys 路径是个好主意吗?

python - 检查 Windows 应用程序的 "liveness"?

python - Django 外键关系

python - 如何使用 JupyterLab 循环更新交互式图形

python - Gunicorn+Django+Heroku。 Python路径问题