我想在通过命令运行我的 python 文件之前激活一个 conda 环境os.system
,但不幸的是,我无法激活 conda 环境。
以下是我尝试执行的命令:
import os
command="python run.py"
foldername="/home/ritish/DeepSpeech/DeepSpeech-master/20140421/test_folder/Test_on_Voice/core_files/raw_file"
files=list(os.listdir(foldername))
if files:
os.system("conda activate deepspeech3")
os.system(command)
else:
print("No Files to Run")
我收到以下错误:
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run
$ conda init <SHELL_NAME>
Currently supported shells are:
- bash
- fish
- tcsh
- xonsh
- zsh
- powershell
See 'conda init --help' for more information and options.
IMPORTANT: You may need to close and restart your shell after running 'conda init'.
* Serving Flask app "core_files" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 119-628-161
答案1
也许你可以尝试这个:
os.system('/bin/bash/ -c "source ~/miniconda3/etc/profile.d/conda.sh && conda activate deepspeech3 && your command"')
~/miniconda3/etc/profile.d/conda.sh
是安装 Anaconda/miniconda 的路径。