简体   繁体   English

在另一个笔记本中运行 Jupyter Lab 笔记本

[英]Run Jupyter Lab notebook in another notebook

I'm sorry bothering you with a stupid question, but I'm facing the following issue with the %run command to run one notebook into another:很抱歉用一个愚蠢的问题打扰你,但我在使用 %run 命令将一个笔记本运行到另一个笔记本时遇到了以下问题:

%运行命令

错误信息

It seems to me it adds the.py extension and then it proceeds the research.在我看来,它添加了 .py 扩展名,然后继续进行研究。 Thanks for your help!谢谢你的帮助!

I tried different method to import another notebook, but I'm kinda new to jupyter lab and can't get around it我尝试了不同的方法来导入另一个笔记本,但我是 jupyter lab 的新手,无法绕过它

If you have to run classes.ipynb from current_notebook.ipynb .如果您必须从current_notebook.ipynb运行classes.ipynb

Possible solution is the following:可能的解决方案如下:

Case 1: current_notebook.ipynb and classes.ipynb are in the same directory情况一: current_notebook.ipynbclasses.ipynb在同一个目录下

%run classes.ipynb

Case 2: current_notebook.ipynb and classes.ipynb are in the different directories情况 2: current_notebook.ipynbclasses.ipynb在不同的目录中

Note: Absolute path to the file does not work in this case for some reason but relative path works as expected.注意:由于某种原因,文件的绝对路径在这种情况下不起作用,但相对路径按预期工作。

For example the paths to the notebooks:例如笔记本的路径:

root_folder > Sandy > current_notebook.ipynb root_folder > 桑迪 > current_notebook.ipynb

root_folder > Tesi > classes.ipynb root_folder > Tesi > classes.ipynb

%run ../Tesi/classes.ipynb

Note: The solution has tested on OS Widows 10, jupyter notebook, python 3注:该方案已在 OS Widows 10、jupyter notebook、python 3 上测试

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM