Run source activate root
in linux, or activate root
in Windows to activate the environment before running your code.
If this does not help you, try for a quick and dirty fix e.g.:
subprocess.run('bash -c "source activate root; python -V"', shell=True)
The reason you need to call bash is that python's run will not call the bash environment, but another which is a bit more constrained and does not contain source
, so here we need to call bash... But as mentioned, if you need this command, either you are doing something special, or something is wrong with your environment...
deactivate is not needed, it does nothing cause the shell it was run on will be destroyed...
Note: For newest conda versions, the provided code will work, but there are also these options that work similarly:
conda deactivate
:
subprocess.run('bash -c "conda deactivate; python -V"', shell=True)
conda activate root
or base
:
subprocess.run('bash -c "conda activate root; python -V"', shell=True)
subprocess.run('bash -c "conda activate base; python -V"', shell=True)
python
to 3.6.6, you would have to change the python alias. – Dogberryconda create -n myenv python=3.6
and then, to use the environment you need to "activate" it. typeconda activate myenv
. Then if you executepython -V
you should get python 3.6.6 When you are finish you may use `conda deactivate' to exit the environment. – Marmionenv
andsubprocess.run("env")
? – Orelie