티스토리 뷰

Linux Ubuntu에서 Pytorch를 설치한다.

(import torch가 안되서, torch 와 Pytorch는 다르니까 torch 설치 방법을 찾으면서 삽질하다가 torch 모듈이 Pytorch를 의미한다는 것을 깨달았다 T_T)

 

간단하게 $ pip install torch 를 해주면 될 것 같았는데 나의 경우 메모리 용량이 아직 많이 남아있는데도 'MemoryError' 에러가 발생한다.

 

설치 방법 1>

github.com/pytorch/pytorch/issues/25164 를 따라,

pip --no-cache-dir install torchvision

또는 나처럼 GPU없이 CPU를 사용하는 경우에는

pip install torch==1.2.0+cpu torchvision==0.4.0+cpu -f https://download.pytorch.org/whl/torch_stable.html

를 써주면 torch 모듈이 웬만하면 잘 설치가 된다. 

 

 

설치 방법 2>

https://pytorch.org 홈페이지에서 옵션 설정하면 나오는 command에 따라 설치하면 원래 윈도우에서는 잘됐는데 Linux에서는 내가 리눅스를 자주 안써서 모듈들 업데이트도 거의 안되있고 그래서 그런지 오류가 났다.

최신 버전이라 호환이 안되는건가 싶어 밑에있는 Previous versions of PyTorch> 버튼을 눌러 나오는 대로 해봐도 안됐다. torch, torchvision, torchaudio의 버전이 다 안맞았다.

pip install torch==1.4.0+cpu torchvision==0.5.0+cpu torchaudio==0.4.0 -f https://download.pytorch.org/whl/torch_stable.html

그래서 겨우 찾은 방법은 이렇게 써주면 된다! (웬만하면 낮은 버전으로 써주면 오류날 일이 없는 것 같다.)

'Successfully installed torch-1.4.0+cpu'라는 메시지가 뜨면 설치가 성공한 것이고 $ python을 입력해 >>> import torch 를 입력해본다.

 

builtins 모듈이 없다고 해서 $ pip install builtins 를 쳐보면 또 에러가 뜬다.

막막할 뻔 했는데 github.com/hyperopt/hyperopt/issues/273 이 분이 날 살려주셨다ㅠㅠ

pip install future

future라는 모듈을 설치해주고 다시 python을 실행해 import torch를 하면 오류 없이 잘 된다!

짝짝

 

 

 

 

반응형

댓글