2️⃣在Python虚拟环境下使用 VS Code or PyCharm

Implementing PyTorch or PyCharm with VS code in virtual python environment

Check NVIDIA Driver and CUDA Version

  1. cmd

  2. nvidia-smi

VS Code

  1. Install VS Code

  2. Open VS Code

  3. Install extention (Python, Jupyter)

  4. Ctrl + Shift + P

  5. Python: Select Interpreter (Select virtual python environment)

  6. Select pytorch (Python 3.11.9)

PyCharm

  • Install PyCharm

  • Create a new project

  • Select Custom environment

  • Select existing

  • Select Conda Type

  • Select Environment

Check version and GPU (batch file)

## check_v.py

import torch
import sys

print("Python Version is",sys.version)
print("CUDA Version is", torch.version.cuda)
print("Pytorch Version is", torch.__version__)
print("Whether CUDA is supported by our system:", torch.cuda.is_available())

device_id =  torch.cuda.current_device()
print("Current Device name:", torch.cuda.get_device_name(device_id))

cuda_id = "GPU available for cuda:"+str(device_id)
device = cuda_id if torch.cuda.is_available() else 'Only CPU can be used'
print(device)
## entryTorch.bat

call conda activate pytorch
python check_v.py

Install cuDNN

  1. Download cuDNN Library

  2. Select Windows -> x86_64 -> Tarball -> 12 (CUDA Version)

  3. Download and Unzip

  4. go to C:\Program Files\NVIDIA Corporation

  5. Create new folder: CUDNN

  6. Create a new folder, name it is v9.0 which in the folder CUDNN

  7. copy unzip files into the v9.x folder

  8. add path C:\Program Files\NVIDIA Corporation\CUDNN\v9.x\bin into Environment Variables

Last updated

Was this helpful?