【问题标题】:how can I write code of terminal inside python script at windows如何在 windows 的 python 脚本中编写终端代码
【发布时间】:2020-04-06 15:48:00
【问题描述】:

如何将下面的代码作为 python 脚本的命令发送到终端上:

cd %HOMEPATH%

conda 安装 git

git 克隆https://github.com/facebookresearch/demucs

cd demucs

conda env update -f environment-cpu.yml

conda 激活 demucs

python.exe -m demucs.separate -d cpu --dl "PATH_TO_AUDIO_FILE_1" ["PATH_TO_AUDIO_FILE_2" ...]

我应用了这个代码:

import os
os.system("cd %HOMEPATH%")
os.system("conda install git")
os.system("git clone https://github.com/facebookresearch/demucs")
os.system("cd demucs")
os.system("conda env update -f environment-cpu.yml")
os.system("conda activate demucs")
os.system("python.exe -m demucs.separate -d cpu --dl 'C:/Users/Arwa_Analyst/Downloads/CAPSTONE PROJECT/research samples/audioDataset/Eval_S_Wav/-1hDIl9Udkw.wav' ")

我得到了这个错误:

enter image description here

enter image description here

【问题讨论】:

    标签: python windows terminal


    【解决方案1】:
    import os
    
    os.system("cd %HOMEPATH%")
    os.system("conda install git")
    #...
    #..
    
    

    您可以使用 import os 包并使用 system 函数从 python 运行终端命令。

    【讨论】:

    • 我试过了,但是python无法识别文件夹路径,例如(conda env update -f environment-cpu.yml)和(python.exe -m demucs.separate)
    • 您能否将代码和您遇到的错误添加到问题中? @ArwaAl-Ghamdi
    • 我照你说的做了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多