ubuntu非root用户移植anaconda环境
环境
- root用户下已经搭建了cuda,anaconda等开发环境;
目标
- 在服务器上创建个人普通用户,在普通用户下,搭建新的ancaonda开发环境,方便使用在每个人使用自己的环境,调试代码,保存文档。
创建用户过程
略
安装anaconda
anaconda 只需要在普通权限下即可安装,使用wget命令下载anaconda的安装包,然后bash指令安装即可
- 下载anaconda源码
- 在清华源中可以选择不同的anaconda版本进行下载,这次我用的是:
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.3.1-Linux-x86_64.sh
- 下载完成后,即可在目录中找到Anaconda3-5.3.1-Linux-x86_64.sh使用如下命令安装即可
bash Anaconda3-5.3.1-Linux-x86_64.sh
- 到此未知,anaconda的环境已经安装完毕。
更改普通用户的环境变量,添加cuda安装路径
root用户已经安装好了cuda环境,无需再次安装,只需要更改普通用户路径下的.bashrc文件,在其中添加环境变量信息即可。若没有这一步,则在安装tenserflow-gpu包的时候会报错。
- 首先查看root用户路径下的.bashrc文件中的cuda安装路径(一般为默认安装路径)
- 路径如下
export PATH=/usr/local/cuda-9.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH
2.将上述代码加入到普通用户路径下的.bashrc文件末尾即可
2. 普通用户模式使用
source ~/.bashrc
更新环境变量(在不重开terminal的情况下必须做,比如putty远程登陆时)
3. 使用
nvcc -V
查看是否正确导入路径,若正确显示cuda版本,则能正常使用
更改anaconda的源 和 pip 的源
如果没有这一步,在移植的时候,会出现http错误和pip错误
参考:清华源的官网说明
- 查看源
conda config --show-sources
- 修改用户目录下的 .condarc文件内容为如下内容
channels:
- defaults
# 设置搜索时显示通道地址
show_channel_urls: true
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
- 也可以执行以下命令:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
conda config --set show_channel_urls yes
- 查看配置
conda config --show
使用environment.yaml文件移植环境
- 将environment.yaml文件拷贝至服务端的普通用户目录下
- cd到该目录
- 使用conda env create -f environment.yaml创建环境
- anaconda会自动下载和安装需要的包。