11

I am trying to import torch in my windows machine using python 3.5. (CPU only)(pip) I have followed the steps given in the official website.

When I try to import torch it gives me the error:

from torch._C import *
ImportError: DLL load failed: The specified module could not be found.

I have looked up from torch._C import * (ImportError: DLL load failed: The specified module could not be found. and ModuleNotFoundError: No module named 'torch._C' and followed their instructions, still the error persists.

The total traceback:

Traceback (most recent call last):
File "D:\CFPS.py", line 1, in <module>
import torch
File "C:\Program Files (x86)\Python35\lib\site-packages\torch\__init__.py", 
line 78, in <module>
from torch._C import *
ImportError: DLL load failed: The specified module could not be found.
[Finished in 0.6s]

Is there a way to get past through this?

Abhishek Singh
  • 943
  • 2
  • 12
  • 24

6 Answers6

9

I've been encountering the same problem. Pytorch seems to require openmp, however this is not part of the PIP distribution.

If you install Pytorch through Anaconda, the Anaconda install includes openmp, so this problem goes away.

To resolve this problem with pip, you can pip install intel-openmp

but you still have to copy the openmp binaries from Python\Library\bin over to Python\Lib\site-packages\torch\lib

Here's a link to the pytorch issue

pytorch issue

billmcc
  • 711
  • 4
  • 11
  • 1
    This did it for me when installing torch from whl file (server blocks regular pip without artifactory and the steps at pytorch.org). Note: Since I was using **conda environment**, I had to copy the dll files to a different location (look where i'm typing miniconda, you might have anaconda) `c:\users\my_user\AppData\Local\Continuum\**miniconda3**\envs\my_env\Lib\site-packages\torch\lib` – mrbTT Jan 27 '20 at 20:14
3

I had the same issue for Windows 10 machine without CUDA, and in my case it's caused by the pytorch I installed is a CUDA version, then I uninstalled it and installed a CPU version pytorch, the problem solved. enter image description here

derek.z
  • 907
  • 11
  • 19
2

I had the same issue. Use CPU version of pytorch if you are using a machine without GPU. The following command should work.

conda install -c peterjc123 pytorch-cpu
2

This error occurs when you have installed PyTorch without OpenMP support. One solution is to install PyTorch through Anaconda as it includes OpenMP. Additionally, my machine does not have a GPU, hence installed only the CPU version.

Also, in my case I had to first uninstall the libraries that I had previously pip-installed:

pip uninstall torch torchvision torchaudio
conda install pytorch torchvision torchaudio cpuonly -c pytorch
Marioanzas
  • 1,663
  • 2
  • 10
  • 33
1

I had the same issue for Windows 10. Solved this by running conda install pytorch -c pytorch

Hannele
  • 9,301
  • 6
  • 48
  • 68
Nusrath
  • 499
  • 1
  • 4
  • 16
0

Same issue, but I have cuda GPU. Go to https://developer.nvidia.com/cuda-downloads and install the version of cuda you selected for pytorch, reboot, and worked for me. Hope it helps you!