So far, I have mainly studied machine learning of table data, but I purchased the book "Development Deep Learning by Pytorch" to study image processing as well. Immediately, I installed Pytorch to execute the sample code, but I got a module import error when executing the code. I had a hard time resolving the event, so I will leave a remedy.
** * By the way, this is Qiita's first post **
OS: Windows10 Anaconda3 environment (Python 3.7.6)
First, check the installation command of Pytorch corresponding to your environment on the official website of Pytorch, and execute the command on Anaconda Prompt.
In my case, the following command (Version is pytorch == 1.6.0 torchvision = = 0.7.0)
conda install pytorch torchvision cpuonly -c pytorch
After the installation of Pytorch is completed, when the sample code attached to the book is executed on Jupyter Notebook, the following error occurs on the line ** "import torch" **. (It has been confirmed that Pytorch is installed properly with the conda list command)
OSError:[WinError 126]The specified module cannot be found. Error loading"C:\Users\●●●\anaconda3\lib\site-packages\torch\lib\asmjit.dll" or one of its dependencies.
I tried various things, but as a result, it was solved by installing the old version Pytorch of ④.
In the following article, when I reinstalled with pip, it was written that the error disappeared, so I installed it again with pip.
[Python] What to do if import torch fails due to an error
However, re-installing with pip did not solve the problem.
Since the Pytorch module existed properly in the folder where the module is installed, it is assumed that the path of the environment variable cannot be passed properly, or that it is affected by the Python version. However, installing Anaconda again did not resolve the issue.
When I installed CUDA about half a year ago, my PC's OS was still Windows 8.1. After that, I updated the OS to Windows 10, so I assumed that it was bad. However, installing CUDA for Windows 10 again did not solve the problem (Is it irrelevant because the sample code executed does not use GPU in the first place?).
In an overseas article, I found a case where installing an older version of Pytorch solved the problem, so I tried it.
error while import pytorch module. (The specified module could not be found.)
In my case, the following command (Version is pytorch == 1.5.0 torchvision == 0.60)
conda install pytorch==1.5.0 torchvision==0.6.0 -c pytorch
As a result, this has resolved the event that caused this error! I was able to execute the sample code as well.
It seems that it was solved in an instant when I wrote it in sentences, but it took me several days to solve it because I spent time changing the versions of Anaconda and CUDA in ② and ③ and reinstalling. (If I had tried ④ from the beginning, it would have been solved with haste ...)
There were few articles in Japanese that a similar event occurred, so I will leave it as a memo this time. Please refer to those who are having trouble with the same event.