1. 下載
安裝建議: 可以安裝miniconda, mini不會預裝python,空間更小.
直接去anaconda官網下載安裝文件即可,具體網站自行搜索。
官網提供linux版本,windows版本,mac版本。
同時提供Anaconda完整版和miniconda最小版(無軟件界面的,僅支持命令行執行),新手推薦使用Anaconda版,熟悉之后推薦改用miniconda版,占用存儲空間小,使用起來感受一樣。
linux環境:
bash Anaconda3-2019.07-Linux-x86_64.sh
#yes+回車
#然后重啟terminal
window環境:直接雙擊安裝exe文件,然后根據安裝向導進行安裝.
2. 升級
升級Anaconda需要先升級conda.
conda update conda #基本升級
conda update anaconda #大的升級
conda update anaconda-navigator //update最新版本的anaconda-navigator
3. 卸載Anaconda軟件
windows:
由於Anaconda的安裝文件都包含在一個目錄中,所以直接將該目錄刪除即可。刪除整個Anaconda目錄:
計算機控制面板->程序與應用->卸載 //windows
或者
找到C:\ProgramData\Anaconda3\Uninstall-Anaconda3.exe執行卸載
ubuntu:
rm -rf anaconda //ubuntu
最后,建議清理下.bashrc中的Anaconda路徑。
4. conda環境使用基本命令
conda update -n base conda #update最新版本的conda
conda create -n xxxx python=3.5 #創建python3.5的xxxx虛擬環境
conda activate xxxx #開啟xxxx環境
conda deactivate #關閉環境
conda env list #顯示所有的虛擬環境
conda info --envs #顯示所有的虛擬環境
5. 查看指定包可安裝版本信息命令
查看tensorflow各個版本:(查看會發現有一大堆TensorFlow源,但是不能隨便選,選擇可以用查找命令定位)
anaconda search -t conda tensorflow
查看指定包可安裝版本信息命令:
anaconda show <USER/PACKAGE>
查看指定anaconda/tensorflow版本信息
anaconda show tensorflow
輸出結果會提供一個下載地址,使用下面命令就可指定安裝1.8.0版本tensorflow
conda install --channel https://conda.anaconda.org/anaconda tensorflow=1.8.0
6. 更新,卸載安裝包
conda list #查看已經安裝的文件包
conda list -n xxx #指定查看xxx虛擬環境下安裝的package
conda update xxx #更新xxx文件包
conda uninstall xxx #卸載xxx文件包
7. 刪除虛擬環境
conda remove -n xxxx --all //創建xxxx虛擬環境
8. 清理(conda瘦身)
conda clean就可以輕松搞定!第一步:通過conda clean -p來刪除一些沒用的包,這個命令會檢查哪些包沒有在包緩存中被硬依賴到其他地方,並刪除它們。第二步:通過conda clean -t可以將刪除conda保存下來的tar包。
conda clean -p //刪除沒有用的包
conda clean -t //刪除tar包
conda clean -y --all //刪除所有的安裝包及cache
9. 復制/重命名/刪除env環境
Conda是沒有重命名環境的功能的, 要實現這個基本需求, 只能通過愚蠢的克隆-刪除的過程。
切記不要直接mv移動環境的文件夾來重命名, 會導致一系列無法想象的錯誤的發生!
//克隆oldname環境為newname環境
conda create --name newname --clone oldname
//徹底刪除舊環境
conda remove --name oldname --all
注意:必須在base環境下進行以上操作,否則會出現各種莫名的問題。
10. conda自動開啟/關閉激活
conda activate #默認激活base環境
conda activate xxx #激活xxx環境
conda deactivate #關閉當前環境
conda config --set auto_activate_base false #關閉自動激活狀態
conda config --set auto_activate_base true #關閉自動激活狀態
11. Conda 安裝本地包
有時conda或pip源下載速度太慢,install a過程中會中斷連接導致壓縮包下載不全,
此時,我們可以用瀏覽器等工具先下載指定包再用conda或pip進行本地安裝
#pip 安裝本地包
pip install ~/Downloads/a.whl
#conda 安裝本地包
conda install --use-local ~/Downloads/a.tar.bz2
11. 解決conda/pip install 下載速度慢
conda數據源管理
#顯示目前conda的數據源有哪些
conda config --show channels
#添加數據源:例如, 添加清華anaconda鏡像:
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 --set show_channel_urls yes
#刪除數據源
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
記錄一下
#本人的 ~/.condarc
auto_activate_base: false
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
show_channel_urls: true
pip數據源管理
#顯示目前pip的數據源有哪些
pip config list
pip config list --[user|global] # 列出用戶|全局的設置
pip config get global.index-url # 得到這key對應的value 如:https://mirrors.aliyun.com/pypi/simple/
# 添加
pip config set key value
#添加數據源:例如, 添加USTC中科大的源:
pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple
#添加全局使用該數據源
pip config set global.trusted-host https://mirrors.ustc.edu.cn/pypi/web/simple
# 刪除
pip config unset key
# 例如
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
#搜索
pip search flask #搜素flask安裝包
# 升級pip
pip install pip -U
記錄一下pip國內源
阿里雲 http://mirrors.aliyun.com/pypi/simple/
中國科技大學 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban) http://pypi.douban.com/simple/
清華大學 https://pypi.tuna.tsinghua.edu.cn/simple/
中國科學技術大學 http://pypi.mirrors.ustc.edu.cn/simple/
pip安裝包管理
pip list #列出當前緩存的包
pip purge #清除緩存
pip remove #刪除對應的緩存
pip help #幫助
pip install xxx #安裝xxx包
pip uninstall xxx #刪除xxx包
pip show xxx #展示指定的已安裝的xxx包
pip check xxx #檢查xxx包的依賴是否合適
pip和conda批量導出、安裝組件(requirements.txt)
pip批量導出包含環境中所有組件的requirements.txt文件
pip freeze > requirements.txt
pip批量安裝requirements.txt文件中包含的組件依賴
pip install -r requirements.txt
conda批量導出包含環境中所有組件的requirements.txt文件
conda list -e > requirements.txt
conda批量安裝requirements.txt文件中包含的組件依賴
conda install --yes --file requirements.txt