## Anaconda 版本控制軟體,用來切割虛擬環境、安裝所需的函式庫、套件 ### 下載 Anaconda - 從 [Anaconda](https://www.anaconda.com/download/success) 官網下載完整安裝包,可以點 Skip registration 跳到下載頁面  - [Anaconda Installers](https://www.anaconda.com/download/success) 下載頁面  - 安裝完後要設定環境變數: 編輯系統環境變數 >> 系統內容 >> 進階 >> 環境變數 >> 系統變數 - 直接在開始搜尋 "環境變數" 找到 "編輯系統環境變數" 點進去 <img src='https://hackmd.io/_uploads/r17mOBuW1l.png' height=60% width=60%> - 系統內容 >> 進階 >> 環境變數 <img src='https://hackmd.io/_uploads/SJwvdrubyg.png' height=60% width=60%> - 在「環境變數」中的「系統變數」找到「Path」點「編輯」 <img src='https://hackmd.io/_uploads/H1ooOB_bkg.png' height=60% width=60%> - 在「編輯環境變數」中,「新增」下面 3 個路徑,視個人安裝位置有所變化,範例: ``` C:\Users\user\anaconda3 C:\Users\user\anaconda3\Library\bin C:\Users\user\anaconda3\Scripts ``` ``` C:\ProgramData\anaconda3 C:\ProgramData\anaconda3\Library\bin C:\ProgramData\anaconda3\Scripts ``` - 設置完成即可於 cmd 或 anaconda prompt 使用剛剛裝的套件 <img src='https://hackmd.io/_uploads/rkzo5Bub1x.png' height=60% width=60%> - 可以在 command line 介面透過 ```conda```, ```conda --version```, ```conda --help``` 等等指令來測試是否設定成功 <img src='https://hackmd.io/_uploads/rkGmiBuWkl.png' height=60% width=60%> <!-- <img src='' height=70% width=70%> --> ### 環境設置 - 列出所有 conda 虛擬環境 ```shell! conda env list ``` - 建置新的虛擬環境 ```shell! conda create -n [env_name] python=[version] ``` - 建立名為 ```[env_name]``` 的 ```conda``` 虛擬環境,並同時直接安裝 ```[version]``` 版本的 ```python``` - 進入虛擬環境 ```shell! conda activate [env_name] ``` - 退出當前虛擬環境 ```shell! conda deactivate ``` - 刪除虛擬環境 ```shell! conda env remove -n [env_name] ``` - 匯出當前環境 ```shell! conda env export > [file_name].yaml ``` - 把當前環境所有資訊匯成一個名叫 ```[file_name]``` ```.yaml``` 檔案,也可以額外指定匯出的路徑,如果沒有指定就會輸出到當前路徑下 ```shell! conda env export > [file_path]\[file_name].yaml ``` - 匯入環境 ```shell! conda env create --file [file_path]\[file_name].yaml --name [env_name] ``` - 根據 ```[file_name].yaml``` 的內容建一個新的 conda 虛擬環境 ```[env_name]``` - 比如想新開一個虛擬環境,命名做 ```py3.12``` 同時直接下載 ```python 3.12```,及對應最新適配版本 ```numpy```, ```matplotlib``` ``` conda env create -n py3.12 python=3.12 numpy matplotlib ``` - 注意: `yaml` 儲存恢復環境設定的方法未來會被棄置 (deprecated),但還是可以從已儲存的 `yaml file` 看到安裝版本 ### 套件安裝 - 查看 conda 版本 ```shell! conda --version ``` - 更新 conda 版本 ```shell! conda update -n base -c defaults conda ``` - 安裝套件 ```shell! conda install [package_name] ``` - 推薦先 google "```conda install [package_name]```" 然後根據 ```Anaconda.Org``` 網站上推薦的安裝命令安裝 - 比如我想安裝 ```pandas``` 就能在 Anaconda 的網站上 [anaconda / packages / pandas](https://anaconda.org/anaconda/pandas) 找到下面的指令 ```shell! conda install -c anaconda pandas ``` - 搜尋套件版本 ```shell! conda search [package_name] ``` - 安裝特定版本 ```shell! conda install [package_name]=[package_version] ``` - 會建議安裝特定版本前先透過 ```conda search``` 確認想要安裝的版本存在 - 一次安裝好所有套件版本 (透過 pip) ```shell! pip install -r requirements.txt ``` - 在當前路徑下有一個 ```requirements.txt``` 檔案,裡面存有所需的所有套件版本資訊 - 比如若我有一個 ```requirements.txt```,且裡面存有下列資訊,就可以在已經建立的虛擬環境下輸入上述指令安裝所有套件 ``` numpy==1.19.2 pytorch==1.7.1 torchaudio==0.7.2 torchvision==0.8.2 pandas==1.2.1 pillow==8.1.0 tqdm==4.56.0 matplotlib==3.3.4 albumentations==0.5.2 ``` - 解除安裝套件 ```shell! conda uninstall [package_name] ``` - 查看所有已經安裝的套件 ```shell! conda list ``` - 查看特定套件 ```shell! conda list [package_name] ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up