← All notes

VSCode 주피터 커널 등록 / CUDA에 맞는 torch 설치

Etc
VS Code에서 가상환경을 Jupyter 커널로 등록하고 CUDA 버전에 맞는 PyTorch를 설치하는 방법을 정리합니다.
Author

고경수

Published

January 1, 2024

On this page

VScode 주피터 커널 등록

가상환경 생성 후 vscode에서 주피터 쓰고 싶으면 커널에 등록해줘야함.

$ conda create -n [가상환경이름] python=3.8

$ pip install ipykernel

$ python -m ipykernel install –user –name [가상환경이름] –display-name [가상환경이름]

  • 터미널에서 가상환경이 안뜨는 경우

ctrl + shift + p → Python: select interpreter -> 가상환경 선택!

CUDA에 맞는 torch 설치

$ nvidia-smi

로 해당 쿠다 버전 확인 후 torch, torchvision 해당 쿠다에 맞게 install.

이전버전

ex) CUDA 11.3

$ conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.3 -c pytorch

최신버전(CUDA 11.7 ↑?)

ex) CUDA 11.8

$ pip3 install numpy --pre torch torchvision torchaudio --force-reinstall --index-url https://download.pytorch.org/whl/nightly/cu118

CUDA 버전이 명시되지 않은 버전의 경우, 예를 들어 CUDA 11.4의 경우 cudatoolkit의 버전만 11.4로 맞출 경우 ‘PackagesNotFoundError’에러가 뜬다. 이럴 경우’-c nvidia’와 ’-c conda-forge’를 추가해주면 해결된다.

$ conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit==11.4 -c pytorch -c nvidia -c conda-forge