I have a autoscript.py module where I have this code snippet:
import subprocess
subprocess.run('/root/anaconda3/bin/conda info --envs', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
The above code runs fine and gives me a response as follows:
CompletedProcess(args='/root/anaconda3/bin/conda info --envs', returncode=0, stdout=b'# conda environments:\n#\nbase /root/anaconda3\nO9PythonUnitTests * /root/anaconda3/envs/O9PythonUnitTests\npy36 /root/anaconda3/envs/py36\n\n')
However, when I modify the above code to activate or deactivate a conda environment as follows:
import subprocess
subprocess.run('/root/anaconda3/bin/conda deactivate', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
I am getting the following conda init <SHELL_NAME>
error:
CompletedProcess(args='/root/anaconda3/bin/conda deactivate', returncode=1, stdout=b"\nCommandNotFoundError: Your shell has not been properly configured to use 'conda deactivate'.\nTo initialize your shell, run\n\n $ conda init <SHELL_NAME>\n\nCurrently supported shells are:\n - bash\n - fish\n - tcsh\n - xonsh\n - zsh\n - powershell\n\nSee 'conda init --help' for more information and options.\n\nIMPORTANT: You may need to close and restart your shell after running 'conda init'.\n\n\n")
I am running the autoscript.py in Ubuntu 18 terminal as follows:
python autoscript.py