오류노트

OSError: [WinError 126] 지정된 모듈을 찾을 수 없습니다. (torch\lib\fbgemm.dll)

wony-wony 2024. 8. 26. 11:50

jupyter notebook을 사용하려고 하는데, 
torch를 import하는 과정에서 에러가 발생했다.

 

 

 

1. Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017, 2019, and 2022 을 설치한다.

2. jupyter notebook 재시작

3. pip uninstall torch

    pip install torch torchvision torchaudio 입력 ----> 하지만 안됨

4. conda install pytorch torchvision torchaudio cpuonly -c pytorch

5. import torch

 

이렇게 하니 torch를 import 하는 것에 성공했다.

 

 

하지만, 며칠 뒤 다시 torch를 import 하니까 동일한 에러가 발생했다.

아 이럴수가

 

 

나는 컴알못이라... 열심히 구글링하고 GPT한테 물어봤다.

나와있는 정말 여러가지 방법들을 다 해봤는데 안 되던 와중에,

해결하는 방법을 찾아냈다.

 

 

1. visual studio를 설치한다.

(https://visualstudio.microsoft.com/ko/vs/features/cplusplus/)

 

community 2022를 다운 받고, 다운 받은 파일을 실행해서 설치를 한다.

 

 

https://drawing-thoughts.tistory.com/61 

 

OSError: [WinError 126] 지정된 모듈을 찾을 수 없습니다. (torch\lib\fbgemm.dll)

이번에 데스크탑을 새로 맞췄다. 그래서 프로그래밍 환경을 다시 구성해서 그런지 전에는 발생하지 않던 이상한 문제가 하나씩 발견된다.. 한 라이브러리를 사용하려고 하는데 OSError: [WinError

drawing-thoughts.tistory.com

여기에서는 설치만 하면 import torch 에러가 해결된다고 하는데,

나는 또다른 에러가 발생했다.

 

 

A module that was compiled using NumPy 1.x cannot be run in NumPy 2.0.1 as it may crash. To support both 1.x and 2.x versions of NumPy, modules must be compiled with NumPy 2.0. Some module may need to rebuild instead e.g. with 'pybind11>=2.12'. If you are a user of the module, the easiest solution will be to downgrade to 'numpy<2' or try to upgrade the affected module. We expect that some modules will need time to support NumPy 2.

 

 

 

 

이 오류는 PyTorch와 NumPy 간의 호환성 문제로 인해 발생하는 것이라고 한다.

 

최근에 NumPy가 2.0.1로 업데이트되면서, 일부 모듈이 이 새로운 버전과 호환되지 않는 상황이 발생한다.

PyTorch 또는 다른 종속 모듈이 이전 버전의 NumPy(1.x)에서 컴파일되었기 때문에 이러한 문제가 발생할 수 있다고 한다.

 

 

나는 이 문제를 해결하기 위해 PyTorch가 NumPy 2.x 버전과 호환되도록  PyTorh를 업데이트 했다.

pip install --upgrade torch

 

이 코드를 사용했다.

 

 

참고로 내 파이썬 버전은 3.12.4이다.

 

 

 

Pytorch와 NumPy의 버전을 맞춰주고 나니 torch를 import 하는데 성공했다.

 

 

 

이 글이 많은 이들에게 도움이 되길 바라며 글을 마친다.