Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Grace Wu\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\torch\__init__.py", line 81, in <module>
ctypes.CDLL(dll)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2032.0_x64__qbz5n2kfra8p0\lib\ctypes\__init__.py", line 364, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found
My python version is 3.7.7 and I installed pytorch using
Based on this post from @peterjc123 you might still have the CUDA version installed, so I would recommend to run the uninstall command a few times and check the current environment for another PyTorch installation.
Hi Peter, I repeated the steps in a virtual environment and am getting the same error.
C:\Users\Grace Wu>torchenv\Scripts\activate
(torchenv) C:\Users\Grace Wu>python
Python 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 11:52:54) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'torch'
>>> quit()
(torchenv) C:\Users\Grace Wu>pip install torch==1.5.0+cpu torchvision==0.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
Looking in links: https://download.pytorch.org/whl/torch_stable.html
Collecting torch==1.5.0+cpu
Using cached https://download.pytorch.org/whl/cpu/torch-1.5.0%2Bcpu-cp37-cp37m-win_amd64.whl (109.2 MB)
Collecting torchvision==0.6.0+cpu
Using cached https://download.pytorch.org/whl/cpu/torchvision-0.6.0%2Bcpu-cp37-cp37m-win_amd64.whl (456 kB)
Processing c:\users\grace wu\appdata\local\pip\cache\wheels\56\b0\fe\4410d17b32f1f0c3cf54cdfb2bc04d7b4b8f4ae377e2229ba0\future-0.18.2-py3-none-any.whl
Collecting numpy
Downloading numpy-1.18.4-cp37-cp37m-win_amd64.whl (12.8 MB)
|ββββββββββββββββββββββββββββββββ| 12.8 MB 2.2 MB/s
Collecting pillow>=4.1.1
Using cached Pillow-7.1.2-cp37-cp37m-win_amd64.whl (2.0 MB)
Installing collected packages: future, numpy, torch, pillow, torchvision
Successfully installed future-0.18.2 numpy-1.18.4 pillow-7.1.2 torch-1.5.0+cpu torchvision-0.6.0+cpu
(torchenv) C:\Users\Grace Wu>python
Python 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 11:52:54) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Grace Wu\torchenv\lib\site-packages\torch\__init__.py", line 81, in <module>
ctypes.CDLL(dll)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2032.0_x64__qbz5n2kfra8p0\lib\ctypes\__init__.py", line 364, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found
>>>
Using print statements, I find that the DLL file that is causing problems is caffe2_detectron_ops_gpu.dll
What might this mean?
pip uninstall caffe2 tells me that caffe2 is not installed
The same error persists after I execute both commands.
I cannot manually remove the DLLs after I uninstall PyTorch because the whole site-packages\torch folder is gone so I guess that meant my uninstallation seemed to work.
Any other possible reasons for this other than problems with my initial installation?
I noticed that this is an issue that several users have been experiencing recently, any reason for that?
Normally, this error means that one or more dependent DLL is missing during the initialization, which mostly caused by users that tend to load the CUDA variant of PyTorch on a CPU-only agent. But apparently, your problem is a bit different.
Update:
From the location of your python executable, it seems that you are using the Python distribution from the Microsoft Store. We didnβt test our binaries under this case so there may be some problem. Would you please provide a detailed version of the log using the steps below?
Well, I reproduced it locally. Looks like it could not find our internal DLLs because it relies on AddDllDirectory which is not built-in in Python 3.7. There are two workable solutions: