pythonanaconda

How do you activate an Anaconda environment within a Python Script?


I have searched through stack overflow, but no post helped specifically with Anaconda.

I am trying to my own Command line prompt in Python. But to do that, I need to activate my Anaconda environment. I cant find anywhere on the web how to run a basic python script to be able to activate said environment. Does anyone know how to do so?


Solution

  • You should be able to use the command line to activate specific environments just by typing:

    activate environment-name
    

    You will have to do use source on Linux.

    source activate environment-name
    

    http://conda.pydata.org/docs/using/envs.html#change-environments-activate-deactivate

    EDIT (3/29/2016)

    Sorry, I misread the question. You should be able to use the call method in the subprocess module to run the shell command through a Python script.

    Edit: A basic example of the subprocess:

    subprocess.call(["activate", value])