Conda activate and deactivate not working

感情迁移 提交于 2021-01-28 08:35:16

问题


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

来源:https://stackoverflow.com/questions/59028993/conda-activate-and-deactivate-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!