--- title: 'anaconda PyTorch 環境架設(ubuntu 20.04)' disqus: hackmd --- anaconda PyTorch 環境架設(ubuntu 20.04) === [TOC] ## 1. Anaconda 下載與安裝 [Anaconda下載](https://www.anaconda.com/products/individual#windows) ![](https://i.imgur.com/KaS07Y6.png) ## 2. 使用 Anaconda Prompt(anaconda3) 創建 python3.7 環境 創造一個 conda for PyTorch 環境 ```gherkin= conda create -n pytorch python=3.7 ``` 切進環境 ```gherkin= conda activate pytorch ``` ![](https://i.imgur.com/CnMqMS9.png) ## 3.安裝 PyTorch [獲得安裝指令](https://pytorch.org/get-started/locally/) ![](https://i.imgur.com/7lN6SVV.png) ```gherkin= conda activate pytorch conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch ``` 安裝後驗證 ```gherkin= conda activate pytorch python import torch ``` ![](https://i.imgur.com/Be3GpRr.png) ```gherkin= import torchvision torchvision.__version__ ``` ![](https://i.imgur.com/WHX9NeA.png) 驗證 CUDA 是否可用 ```gherkin= torch.cuda.is_available() torch.cuda.get_device_name() ``` ![](https://i.imgur.com/GhCWWEI.png) ```gherkin= torch.cuda.device_count() ``` ![](https://i.imgur.com/Rz3mC1e.png) CUDA ID ```gherkin= torch.cuda.current_device() ``` ![](https://i.imgur.com/kjXu2P5.png) CUDA 裝置名稱 ```gherkin= torch.cuda.get_device_name(0) ``` ![](https://i.imgur.com/uGC8sfa.png) ## 4.安裝 conda 相關套件 ```gherkin= pip install jupyterlab conda install -c conda-forge matplotlib -n pytorch conda install -c anaconda pandas -n pytorch pip install torchsummary pip install torch pip install opencv-python pip install opencv-contrib-python ``` ###### tags: `setup`, `Python`