简体   繁体   English

如何让Jupyter Notebook导入python文件?

[英]How can I get Jupyter Notebook to import a python file?

I have a very simple .py file, displayD3caller.py: 我有一个非常简单的.py文件,displayD3caller.py:

def caller():
    print("Here is a print statement from displayD3caller.py")

I can import and use the function defined in other files, and from the python shell. 我可以导入和使用其他文件中定义的函数,以及python shell。 However, when I try to import the function in a Jupyter Notebook, it can't find the module: 但是,当我尝试在Jupyter Notebook中导入该函数时,它找不到该模块:

ImportError: No module named 'displayD3caller'

What can I do to fix this? 我该怎么做才能解决这个问题?

Before Jupyter Notebook uses any change to the source code of related files, the kernal needs to be restarted. 在Jupyter Notebook对相关文件的源代码进行任何更改之前,需要重新启动内核。 This includes creating a new file. 这包括创建新文件。

If you make a new module after Jupyter is already running, you need to restart the kernal before it will find it. 如果在Jupyter运行之后创建一个新模块,则需要重新启动内核才能找到它。 From the top menu, select Kernal > Restart. 从顶部菜单中,选择Kernal> Restart。 You will need to re-execute any cells whose outputs you depend on. 您需要重新执行您依赖其输出的任何单元格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 python 文件导入 jupyter notebook - import python file into jupyter notebook 如何在 Google Colab 的 Jupyter 笔记本中导入自定义 Python package 和模块? - How can I import a custom Python package and module in a Jupyter notebook on Google Colab? 如何将 Python 中的代码和 Markdown 单元格导入 Jupyter Notebook? - How can I import code and markdown cells from Python to Jupyter notebook? 将本地 python 文件导入 Jupyter Notebook - Import local python file to Jupyter Notebook 如何解决 Jupyter Notebook、Python3 上的 FileNotFound 错误 - How can I solve FileNotFound Error on Jupyter Notebook, Python3 使用Jupyter Notebook在Python中进行相对导入 - Relative Import in python with Jupyter notebook 为什么我已经安装了Jupyter Notebook(Python 3.6),但无法将utils导入到我的Jupyter Notebook中? - Why I can not import utils in my Jupyter Notebook (Python 3.6) although it is installed? 带有Jupyter笔记本的Python 3:无法在同一目录中导入文件 - Python 3 with Jupyter notebook: Cannot import file in the same directory jupyter notebook 的 Python3 环境下无法导入已安装的包 - Can't import the installed package in Python3 environment of jupyter notebook 如何在 OnDemand Jupyter Notebook 中导入非标准 python 模块 - How do I import a non-standard python module in an OnDemand Jupyter Notebook
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM