Bru*_*pos 13 python bash jupyter-notebook
我只需要在一个单元格中编写一个带有配置环境的脚本。我想让它缩进
!(python --version
which python
pip --version
conda --version
which conda) >> config-environment.txt
Run Code Online (Sandbox Code Playgroud)
但是单元格不接受每个命令之间的跳过线。怎么写?是否可以在 jupyter-notebook 中缩进编写 bash 脚本?
kHa*_*hit 23
对于您的特定情况,您可以简单地在末尾使用分号来运行它,即
!(python --version; \
which python; \
pip --version; \
conda --version; \
which conda) >> config-environment.txt
Run Code Online (Sandbox Code Playgroud)
对于一般情况,您可以使用%%bash
cell magic 命令在 bash 中运行单元格,即
%%bash 脚本魔法
在子进程中使用 bash 运行单元格。
%%bash
(python --version
which python
pip --version
conda --version
which conda) >> config-environment.txt
Run Code Online (Sandbox Code Playgroud)
您还可以查看subprocess
python 模块。