sys.path在Jupyter和Python中有所不同-如何在Jupyter中导入自己的模块? [英] sys.path different in Jupyter and Python - how to import own modules in Jupyter?

查看:615
本文介绍了sys.path在Jupyter和Python中有所不同-如何在Jupyter中导入自己的模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Jupyter中,我自己的小模块未加载,但是在python/bpython中,一切都很好.键入时

In Jupyter my own little module is not loaded but in python/bpython is everything is fine. When typing

import sys
print(sys.path)

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

the path to my module will not in show in Jupyter but in python/bpython it is still there.

我正在使用:

  1. .bashrc中的PYTHONPATH包含我的模块,
  2. virtualenv中的Jupyter和bpython.

最相似的问题是这个 无法在jupyter笔记本中导入模块;错误的sys.path

The most similar questions is this Cannot import modules in jupyter notebook; wrong sys.path

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

How to configure Jupyter to load my modules automagically?

推荐答案

这是我在jupyter笔记本中的项目上所做的事情,

Here is what I do on my projects in jupyter notebook,

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

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

%load_ext autoreload
%autoreload 2

这篇关于sys.path在Jupyter和Python中有所不同-如何在Jupyter中导入自己的模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆