gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 21:33:33 29 4
gpt4 key购买 nike

在 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com