如何在终端中的 Jupyter 上 运行 python 脚本?
How to run python script on Jupyter in the terminal?
我想在 Jupyter 中执行一个 python 脚本,但我不想使用网络浏览器(IPython 交互式终端),我想 运行 一个Linux 终端中的命令加载 & 运行 python 脚本,这样我就可以从 Jupyter 获取输出。
我试过 运行 jupyter notebook %run <my_script.py>
,但 jupyter 似乎无法识别 %run
变量。
可以吗?
您可以使用 jupyter console -i
命令在终端中 运行 交互式 jupyter 会话。从那里你可以 运行 import <my_script.py>
。请注意,这不是 jupyter 或笔记本环境的预期用例。您应该 运行 使用普通的 python 解释器来编写脚本。
您可以 运行 此命令在您的终端中 运行 交互式 jupyter 会话。
jupyter notebook
jupyter_client
包从 v5.0 开始有一个 jupyter run
命令,所以你可以这样做:
jupyter run my_script.py
我想在 Jupyter 中执行一个 python 脚本,但我不想使用网络浏览器(IPython 交互式终端),我想 运行 一个Linux 终端中的命令加载 & 运行 python 脚本,这样我就可以从 Jupyter 获取输出。
我试过 运行 jupyter notebook %run <my_script.py>
,但 jupyter 似乎无法识别 %run
变量。
可以吗?
您可以使用 jupyter console -i
命令在终端中 运行 交互式 jupyter 会话。从那里你可以 运行 import <my_script.py>
。请注意,这不是 jupyter 或笔记本环境的预期用例。您应该 运行 使用普通的 python 解释器来编写脚本。
您可以 运行 此命令在您的终端中 运行 交互式 jupyter 会话。
jupyter notebook
jupyter_client
包从 v5.0 开始有一个 jupyter run
命令,所以你可以这样做:
jupyter run my_script.py