3

I want to activate activate a conda environment before running my python file through os.system command, but unfortunately, I am not able to activate the conda environment.

Following is the command I am trying to implement:

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")

I am getting the following error:

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 Answer 1

1

Maybe you can try this:

os.system('/bin/bash/ -c "source ~/miniconda3/etc/profile.d/conda.sh && conda activate deepspeech3 && your command"')

~/miniconda3/etc/profile.d/conda.sh is the path where your Anaconda/miniconda is installed.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .