Linux多用户共用Anaconda环境

0. 下载 Anaconda3

地址:https://www.anaconda.com/download/
这里我下载的是 Anaconda3-2019.03-Linux-x86_64.sh

1.安装Anaconda环境

1. 进入root用户, 安装Anconda

su root
bash Anaconda3-2019.03-Linux-x86_64.sh

注意下面安装路径不要放在默认的 /root/anaconda3 否则其他用户没有访问权限,这里我选择的是/usr/local/anaconda3

Do you accept the license terms? [yes|no]
Please answer 'yes' or 'no':'
>>> yes
Anaconda3 will now be installed into this location:
/root/anaconda3

  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below

[/root/anaconda3] >>> /usr/local/anaconda3
PREFIX=/usr/local/anaconda3
installing: python-3.7.3-h0371630_0 ...

2.创建anaconda用户组

groupadd anaconda

3. 添加用户到用户组

usermod -a -G anaconda <username>
将一个用户添加到用户组中,千万不能直接用: usermod -G groupA这样做会使你离开其他用户组,仅仅做为 这个用户组 groupA 的成员。
应该用 加上 -a 选项: usermod -a -G groupA user,-a 代表 append, 也就是 将自己添加到 用户组groupA 中,而不必离开 其他用户组。

添加结束通过 vim /etc/group在最后可以查看用户组和用户

4. 移交目录管理权

chgrp -R anaconda /usr/local/anaconda3

5. 设置读写权限

chmod 770 -R /usr/local/anaconda3

6. 设置组继承

chmod g+s /usr/local/anaconda3

7. 设置子目录组继承

chmod g+s `find /usr/local/anaconda3/ -type d` 

8. 关闭共享环境的写入权限

chmod g-w /usr/local/anaconda3/envs

9.root用户下启动anaconda环境

source /usr/local/anaconda3/bin/activate

10. 创建共享环境

conda create -n hisense python=3.7

2.配置环境变量

vim /etc/profile
添加:
export PATH=/usr/local/anaconda3/bin:$PATH
source /etc/profile

3.其他用户激活Anaconda环境

1. 切换用户

su hisense

2.查看conda环境

[hisense@Master wx]$ conda info --env
WARNING: The conda.compat module is deprecated and will be removed in a future release.
# conda environments:
#
base                  *  /usr/local/anaconda3
hisense                  /usr/local/anaconda3/envs/hisense

3.激活环境

[hisense@Master /]$ /usr/local/anaconda3/bin/conda init bash
WARNING: The conda.compat module is deprecated and will be removed in a future release.
no change     /usr/local/anaconda3/condabin/conda
no change     /usr/local/anaconda3/bin/conda
no change     /usr/local/anaconda3/bin/conda-env
no change     /usr/local/anaconda3/bin/activate
no change     /usr/local/anaconda3/bin/deactivate
no change     /usr/local/anaconda3/etc/profile.d/conda.sh
no change     /usr/local/anaconda3/etc/fish/conf.d/conda.fish
no change     /usr/local/anaconda3/shell/condabin/Conda.psm1
no change     /usr/local/anaconda3/shell/condabin/conda-hook.ps1
no change     /usr/local/anaconda3/lib/python3.7/site-packages/xonsh/conda.xsh
no change     /usr/local/anaconda3/etc/profile.d/conda.csh
modified      /home/hisense/.bashrc

==> For changes to take effect, close and re-open your current shell. <==

[hisense@Master /]$ source ~/.bashrc
(base) [hisense@Master /]$ conda activate hisense

4.激活成功

(hisense) [hisense@Master /]$ 

参考:

在UBuntu服务器上anaconda创建的虚拟环境如何多用户共享访问使用? - 张兴远的回答 - 知乎
https://www.zhihu.com/question/277053071/answer/946713532

Linux添加用户(user)到用户组(group):
https://blog.csdn.net/weixin_41282397/article/details/81113014

上一篇:pip Anaconda3 安装目录


下一篇:Ubuntu18.04安装anaconda3和pytorch