我有一个autoscript.py模块,其中有以下代码片段:
import subprocess
subprocess.run('/root/anaconda3/bin/conda info --envs', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
上面的代码运行良好,并给了我以下响应:
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')
但是,当我修改以上代码以激活或停用conda环境时,如下所示:
import subprocess
subprocess.run('/root/anaconda3/bin/conda deactivate', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
我遇到以下conda init <SHELL_NAME>
错误:
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")
请帮助。
我正在Ubuntu 18终端中运行autoscript.py,如下所示:
python autoscript.py