【问题标题】:Issue running terminal commands through jupyter notebook通过 jupyter notebook 发出运行终端命令
【发布时间】:2020-06-02 06:08:25
【问题描述】:

我目前正在运行来自 github 存储库的 jupyter notebook。一大块是这样的:

for file in os.listdir('data/'):
    path = 'data/' + file

    os.system(f"python OpticalFlowGen.py --type {target} --file {path}")

变量目标和路径已定义并且没有引发错误。

python OpticalFlowGen.py ---type 'Train' -- file 'data/video.mp4'的终端上运行OpticalFlowGen.py文件,视频文件经过openCV处理后弹出并关闭,系统会保存.jpg文件。但是,当在 jupyter notebook 上运行此命令时,不会弹出任何内容,也不会保存任何文件。您可以从同一存储库 here 访问此 .py 文件。

目前我必须逐个文件在终端上手动运行,因此在我可以运行笔记本之前保存所有图像输出而不会出错。但是,当我有太多的视频文件时,它会成为一个问题,不使用for循环会太麻烦。关于如何解决这个问题的任何想法?

【问题讨论】:

    标签: python opencv jupyter-notebook


    【解决方案1】:

    在 Jupyter Notebook 中,您不必使用 os.system,而是尝试使用 !

    for file in os.listdir('data/'):
        path = 'data/' + file
    
        # Use
        # ! - for terminal commands
        # {} - for a variable in the terminal command
        !python OpticalFlowGen.py --type {target} --file {path}
    

    【讨论】:

      猜你喜欢
      • 2016-12-06
      • 2019-08-20
      • 2022-11-12
      • 2015-06-23
      • 2020-09-07
      • 2017-01-25
      • 1970-01-01
      • 2016-06-03
      相关资源
      最近更新 更多