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"

if files:
    os.system("conda activate deepspeech3")
    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 (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 119-628-161

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