远程登陆Ubuntu服务器anaconda的使用问题(多用户)

远程登录Ubuntu的新用户在使用 conda 命令时,可能会遇到找不到 conda 命令的情况,因此在多用户使用 anaconda 的情况下,需要提前在 Ubuntu 服务器上做一下 anaconda 的配置。

anaconda 的安装过程省略。

1、添加环境变量

首先需要编辑 /etc/profile 文件

sudo vim  /etc/profile

按 i 键编辑,在文件最后添加以下语句

export PATH=/home/[安装anaconda的用户名]/anaconda3/bin:$PATH

按 ESC 键退出编辑,然后依次输入 :wq 保存退出,然后 source 一下这个文件夹,这样就将anaconda 添加到全局的环境变量中了。

source /etc/profile

可以使用以下命令查看当前的环境变量

echo $PATH

2、用户首次远程连接时需要初始化 conda 的 shell 环境

用户初次远程连接服务器使用 conda 命令时会出现以下提示:

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.

完整的提示如下:

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init'.

此时按照提示运行一下下面的指令执行 shell 初始化即可

conda init bash

然后还需要 source 一下当前用户的 .bashrc 文件

source .bashrc

如果不知道当前用户使用的什么类型的 shell 的话,可以使用以下指令查看用户信息:

cat /etc/passwd

每条信息最后一个冒号后面的就是当前用户的 shell 类型,一般默认都是 bash。

猜你喜欢

转载自blog.csdn.net/Flag_ing/article/details/127779795