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會自動下載和安裝需要的包。