简体   繁体   English

如何在Jupyter笔记本中运行命令?

[英]How do I run a command in a Jupyter notebook?

In a notebook I have the following in a cell: 在笔记本中,单元格中包含以下内容:

   cwd = os.getcwd()
   run cwd + "/plot_data.py"

I get the error: 我得到错误:

ERROR:root:File `'cwd.py'` not found.

Apparently, run thinks I am trying to run a python file "cwd.py" with the options "+" and "plot_data.py". 显然,run认为我正在尝试运行带有选项“ +”和“ plot_data.py”的python文件“ cwd.py”。

Actually I am trying to run a file plot_data.py located in cwd 实际上我正在尝试运行位于cwd中的文件plot_data.py

Create the full file name, and pass it to run with the $ prefix: 创建完整的文件名,并传递给它以$前缀run

file = cwd + "/plot_data.py"
run $file

In

run cwd + "/plot_data.py"

cwd is the file parameter, to be run, and '+' and "/plot..." are arguments that get passed to it. cwd是要运行的文件参数,“ +”和“ / plot ...”是传递给它的参数。 This isn't a Python expression (which would preform the string join). 这不是Python表达式(它将执行字符串join)。

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

相关问题 如何将命令的输出分配给 Jupyter Notebook 中的变量? - How do I assign the output of a command to a variable in Jupyter notebook? 如何帮助 Python 找到 Jupyter 命令“jupyter-nbconvert”,将 Jupyter Notebook 导出为 HTML? - How do I help Python find Jupyter command 'jupyter-nbconvert', to export Jupyter Notebook to HTML? 如何检查哪个 Jupyter notebook 已经“%run”了另一个 notebook? - How do I check which Jupyter notebook has “%run” another notebook? 在运行笔记本代码之前,如何让我的 Jupyter 笔记本服务器运行任意 Python 代码? - How do I have my Jupyter notebook server run arbitrary Python code before running notebook code? 如何运行Jupyter Notebook - How to run Jupyter Notebook 如何修复 Jupyter Notebook 中的这个 ImportError? - How do I fix this ImportError in Jupyter Notebook? 如何让设置命令仅在第一次运行 Jupyter Notebook 时运行? - How can I make a setup command only run the first time a Jupyter notebook is ran? 如何在 Jupyter Notebook 中导入 Pyperclip? - How do I import Pyperclip in Jupyter Notebook? 如何更改Jupyter Notebook中的字体 - How do I change font in Jupyter Notebook 如何在 Jupyter Notebook 中阅读此 CSV? - How do I read this CSV in Jupyter Notebook?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM