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

Created on 7 Jan 2018  ·  172Comments  ·  Source: pytorch/pytorch

File "", line 4, in
import torch

File "C:\Users\hp i3\Anaconda3\lib\site-packages\torch__init__.py", line 76, in
from torch._C import *

ImportError: DLL load failed: The specified module could not be found.

Most helpful comment

@AlbertHuyb Download win-64/intel-openmp-2018.0.0-8.tar.bz2 and put the dll files in Library\bin into a dir and append the path of it to the environment variable PATH.

All 172 comments

@HarshneetBhatia Which version are you using? Do you have CUDA cards? How did you install it?

@HarshneetBhatia And I noticed there is a space inside your path of Anaconda install. Would you please try a path without it?

@peterjc123
Using Anaconda -Spyder python 3.6
I have installed conda install -c peterjc123 pytorch

I am using windows 8.1

Is space creates problem I have the same path hp i3 - Should I change the the name ?

@HarshneetBhatia If if doesn't work after reinstalling Anaconda, then you can use sth. like Dependency Walker, open [Anaconda PATH]\Lib\site-packages\torch\lib\_C.pyd to detect what's wrong there.

I had the same issue and it was caused by the directory torch which is generated in the same directory by compiling the source. The solution for me was simply changing the directory before open python.

@maatini I am using Anaconda can you please guide me how to change the directory.

Thanks in advance

The problem in my case was that I started python from a (command)-shell from the directory in which I compiled pytorch. In this directory exists (was generated) the sub-directory torch, which python tries to load if you "import torch". So simply leaving the pytorch directory before starting python solved my problem.

@maatini In Anaconda do you have any idea how can this problem be solved ?
Because I not getting how to change the directory in Anaconda.

@HarshneetBhatia Same as how you normally change directory: cd.

I get a similar error in the following context: Perviously, I successfully used windows10 pytorch 0.2.1 (using the anaconda distribution from -c peterjc123). We have now downloaded a pip .whl for all of us to use and so I uninstalled pytorch 0.2.1 and tried installing the wheel file using

pip install $PATH_TO_WHL$/torch-0.3.0b0+591e73e-cp36-cp36m-win_amd64.whl

This completes successfully, but then I get (in spyder, PyDev and python command line):
'>> import torch
Traceback (most recent call last):
File "C:\Users\alexandre\Anaconda3\lib\site-packages\torch__init__.py", line 76, in
from torch._C import *
ImportError: DLL load failed: The specified module could not be found.
'

I am on windows 10, python 3.6.4, conda 4.4.10. And pip is the anaconda pip.

As a fallback I tried:
conda install -c peterjc123 pytorch cuda80
and that 'worked'

But I am curious why the .whl file fails for me (it works on a colleague's machine).

@aviolov It's probably related to Visual C++ Redist 2017. Because the vc package will be updated if you install it through the conda channel. You can confirm this using the following steps:

pip uninstall torch
pip install $PATH_TO_WHL$/torch-0.3.0b0+591e73e-cp36-cp36m-win_amd64.whl

If that works, then it should be MSVC related. Otherwise, maybe the cuda files are missing in PATH.

I don't think this is a CUDA related issue. It sounds more like the pip install command messes up the torch folders 'somehow', as the other comments above suggest, although i experienced the problem not just when running python in the same folder in which I ran the pip comand. (pydev, spyder, ipython in another folder)

Also I did try
conda install pytorch
conda uninstall pytorch
pip instal pytorch.whl

And the failure persisted, which suggests that it's not related to the vc2017 Redist, since the first conda update should have fixed that?

Another weird thing is that when i try to pip uninstall I get an error that it cannot remove some folders from my AppData\Local\Temp. These folders look like the torch distriution (./torch/_nvrtc.cp.. etc).

@aviolov Can you check that _nvrtc.cp.. lies in the Anaconda dir?

I was trying to execute sample code from fast.ai course and I get similar error. I am new and just walking foot-steps to setup my jupyter notebook.

`C:\Program Files\Anaconda3\envs\fastai\lib\site-packages\torch\__init__.py in <module>()
     74     pass
     75 
---> 76 from torch._C import *
     77 
     78 __all__ += [name for name in dir(_C)

ImportError: DLL load failed: The specified module could not be found.`

Below is my conda info

C:\Users\wecando>conda info
     active environment : None
       user config file : C:\Users\wecando\.condarc
 populated config files : C:\Users\wecando\.condarc
          conda version : 4.4.10
    conda-build version : not installed
         python version : 3.6.0.final.0
       base environment : C:\Program Files\Anaconda3  (read only)
           channel URLs : https://conda.anaconda.org/anaconda-fusion/win-64
                          https://conda.anaconda.org/anaconda-fusion/noarch
                          https://repo.continuum.io/pkgs/main/win-64
                          https://repo.continuum.io/pkgs/main/noarch
                          https://repo.continuum.io/pkgs/free/win-64
                          https://repo.continuum.io/pkgs/free/noarch
                          https://repo.continuum.io/pkgs/r/win-64
                          https://repo.continuum.io/pkgs/r/noarch
                          https://repo.continuum.io/pkgs/pro/win-64
                          https://repo.continuum.io/pkgs/pro/noarch
                          https://repo.continuum.io/pkgs/msys2/win-64
                          https://repo.continuum.io/pkgs/msys2/noarch
          package cache : C:\Program Files\Anaconda3\pkgs
                          C:\Users\wecando\AppData\Local\conda\conda\pkgs
       envs directories : C:\Users\wecando\AppData\Local\conda\conda\envs
                          C:\Program Files\Anaconda3\envs
                          C:\Users\wecando\.conda\envs
               platform : win-64
             user-agent : conda/4.4.10 requests/2.12.4 CPython/3.6.0 Windows/10 Windows/10.0.16299

@peterjc123, I think it does:
pwd
Out[11]: 'C:\Users\alexandre\Anaconda3'

glob.glob(r'./*/_nvrtc.cp', recursive=True)
Out[10]:
['.\Lib\site-packages\torch\_nvrtc.cp36-win_amd64.pyd',
'.\pkgs\pytorch-0.3.0-py36_0.3.0cu80\Lib\site-packages\torch\_nvrtc.cp36-win_amd64.pyd']

This is after uninstalling the .whl file and installing via conda install -c ...

Is there any resolution for this? Facing the same error

@ciphurus Which package are you installing? If you are using conda ones, you can try updating vc packages. conda install -c peterjc123 vc

Yes, I am using conda install -c peterjc123 pytorch on Windows 7. I also tried conda install -c peterjc123 pytorch_legacy and that too gave the same error.
Also tried what you suggested conda install -c peterjc123 vc but still getting the same error
from torch._C import *
File "C:\Users\Admin.p2\pool\plugins\org.python.pydev_5.9.2.201708151115\pysrc_pydev_bundle\pydev_import_hook.py", line 20, in do_import
module = self._system_import(name, args, *kwargs)
ImportError: DLL load failed: The specified procedure could not be found.

@ciphurus Hey! Your error seems not to be on the PyTorch side, since this error is not thrown from the torch package. Would you please run import torch test from command prompt to confirm this?

@peterjc123 Same issue here:

  • Anaconda on Windows 7
  • Updated VC already
  • Tried both Torch and Torch_Legacy using Conda install -c peterjc123 pytorch cuda80
    Same error on line 74 of __init__.py (torch._C import *)
  • already tried uninstalling/installing again, different users, different directories, no difference.

I am new to python so I may have missed something here. Please let me know if you need more information to pinpoint the cause.

@sshahpouri Would you please try this command? conda install -c peterjc123 vc msvc2017_runtime

No, I tried on anaconda command prompt and get the same error
(base) C:\Users\Admin>python
Python 3.6.4 |Anaconda custom (64-bit)| (default, Jan 16 2018, 10:22:32) [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 "", line 1, in
File "C:\Users\Admin\Anaconda3\lib\site-packages\torch__init__.py", line 76,
in
from torch._C import *
ImportError: DLL load failed: The specified procedure could not be found.

@ciphurus Please try the same command above and see whether it works.

@sshahpouri @ciphurus Sorry for typo. It should be conda install -c peterjc123 vc vs2017_runtime.

@peterjc123 When I tried the command, I get the following python.exe - System Error:
The program can't start because
api-ms-win-core-rtlsupport-l1-2-0.dll is missing from your computer. Try reinstalling the program to fix this probmel

@peterjc123 I installed it with VS2017runtime, installation successful, installing pytorch successful, but importing torch raises the same error. (line 74)

As a side note, installing VS2017Runtime downgrades VC from 14.1 to 14. I guess this is intentional. Isn't it?

Another note: I just watched a video someone successfully installing PyTorch 0.2.1.
@peterjc123 do you have a link to 0.2.1 so that I can give that one a try?

@sshahpouri See the Easy Installation section of my repo.

@ciphurus Would you please download win-64/vs2017_runtime-15.4.27004.2010-1.tar.bz2 from here and install it?

I reinstalled anaconda and was able to run
conda install -c peterjc123 vc vs2017_runtime
But still facing the same error when import torch

Any suggestions on how to resolve this?

@ciphurus Can you please use Dependency to debug what's wrong there? Just use it to open [Anaconda dir]\Lib\site-packages\torch\_C.pyd and send me the screenshot.

@peterjc123 kind of good news!
I downloaded torch version 0.2.1 and installed it offline and it works! yes, finally I have a working torch.
pytorch_legacy-0.2.1-py36_0.2.1cu80.tar.bz2

@peterjc123 attached is a screenshot, the file I could find in the directory was_C.cp36-win_amd64.pyd
torch_error
Let me know if this helps to identify what might be missing

@ciphurus It's all right in this picture. Could you please expand the items a little bit and see if there're more items missing?

As with my case, one possible reason is that there are no CUDA related DLLs installed. If you don't have an NVIDIA GPU for deep learning, the following CPU version should be installed:
conda install -c peterjc123 pytorch-cpu
instead of
conda install -c peterjc123 pytorch (this one is for CUDA 8.)

@ShuhuaGao Yes, you are right. But since @ciphurus has nvcuda.dll in his PATH, I think he must have a Nvidia GPU.

@peterjc123 Can you please elaborate a little bit. Should I be looking for something specific while expanding the items? What will a missing dependency show like?

Faced with the same issue. I have installed pytorch with
"conda install -c pteterjc123 pytorch cuda80"
and vs with
"conda install -c peterjc123 vc vs2017_runtime".
But still when I import torch in python, error popped up the same like
from torch._C import *
ImportError: DLL load failed: 找不到指定的模块。

I am currently using Win10, anaconda 4.4.10 and python 3.6.4. Could you please help me with this? @peterjc123

@xiamengzhou Do you have CUDA 8.0 installed or in other words, do you have a capable Nvidia graphics card?

Thanks for your response @peterjc123 . I don't have a Nvidia graphics card on my computer. Is that a must for using pytorch just with CPU?

@xiamengzhou See my comment above. In a word, you should (1) first uninstall the pytorch you have now (2) run the following command to install the CPU-only version
conda install -c peterjc123 pytorch-cpu

@ciphurus Can you try cpu version first(see comment above)? If cpu version cannot be successfully imported, then it may be related to VC2017, otherwise your CUDA setup may be corrupted.

@ShuhuaGao Works like a charm! Thanks a lot!

@peterjc123 Yes, the cpu version worked. Right now I want to use it just to get familiar with the syntax and a few cases so this is very useful. Thanks for your help with this.

"conda install -c peterjc123 pytorch-cpu" worked for me Thanks

"conda install -c peterjc123 pytorch-cpu" worked.. Thanks a lot guys!

Faced with the same issue

I have succeeded installation with version: pytorch-0.3.1-py36_cuda90_cudnn7he774522_2 with
"conda install -c peterjc123 pytorch cuda90" with result:
All requested packages already installed.

and vs with
"conda install -c peterjc123 vc vs2017_runtime" with result:
All requested packages already installed.

But still when I import torch in python, error popped up like

Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'torch'

I'm using Windows 10, gtx 1060, python 3.6.4, conda 4.5.0
and previously succeeded using tf 1.7.0-rc0 and keras 2.1.5, both gpu enabled.

Could you please also help me with this? Should I downgrade my pytorch? @peterjc123
Thanks before

@bryanwilie Would you please try uninstalling all the related packages and install them again afterwards?

@peterjc123 Just now I tried to remove vc, vs2017_runtime and pytorch, and install them all back, and I'm getting the same error when I try to import torch. This feels weird ..

Is there any more package I must uninstall again?

Thanks for prompt reply, @peterjc123!

@bryanwilie Could you show the paths of python and conda please? Using the commands below.

where python
where conda

@peterjc123 Sorry, haven't read that. Here it is:

where python

C:\Users\LENOVO\AppData\Local\Programs\Python\Python36python.exe
C:\Users\LENOVO\Anaconda3python.exe

where conda

C:\Users\LENOVO\Anaconda3\Library\binconda.bat
C:\Users\LENOVO\Anaconda3\Scriptsconda.exe

@bryanwilie Your first python in PATH is not the one in anaconda. That is the problem. You can remove the first python or prioritize the python in anaconda.

@peterjc123 It worked! I remove the first python and actually reinstalling my conda because I have already removed it before. Thank you so much

Faster solution is to just change the priority (as @peterjc123 suggest) of the environment variable

I had a similar problem and using (conda install -c peterjc123 pytorch-cpu) made it worked.

conda install -c peterjc123 pytorch-cpu is not installing torchvision
How can i get torchvision (windows 7 64 bit, CPU only)?
Thanks

@senpkum It's pip install torchvision. And next time please ask in the related issue.

@peterjc123
Hello, I meet the same error when I just follow the command from pytorch.org to install pytorch.

pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.0-cp36-cp36m-win_amd64.whl
pip3 install torchvision

But after I run python in cmd and try to import torch. It replied with this error:

Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) [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 "", line 1, in
File "C:\Program Files\Python36\lib\site-packages\torch__init__.py", line 78, in
from torch._C import *
ImportError: DLL load failed: 找不到指定的模块。

I wonder how I could fix this problem without installing anaconda.
Any other information do I need to show you?
Thanks a lot !

@AlbertHuyb You are using pure Python, right? Then you'll need to install the VC Redist 2017 by yourself. You'll also need the intel-openmp dlls and Numpy.
Here are the links to them:
VC 2017
Intel openmp

@peterjc123
I installed VC Redist 2017 from the first link but it still doesn't work……
What should I do with the second link?
Additionally, I am using windows and I have already installed MVS 2017, so I discovered that I have VC Redist 2008 and 2012 and 2013 and 2017(two versinos) on my computer now.
Thanks a lot!

@AlbertHuyb Download win-64/intel-openmp-2018.0.0-8.tar.bz2 and put the dll files in Library\bin into a dir and append the path of it to the environment variable PATH.

@peterjc123 I have the same problem. I'm trying to install torch using pure Python, i.e. pip. It installs fine, however I get the same error message as AlbertHuyb. I have installed VC Redist 2017 and Intel's openmp (and added the dll directory to the PATH) and reinstalled torch, however the problem remains.

I'm using Python 3.6 and trying torch-cpu version (0.4.0). Any ideas? Thanks.

@peterjc123
It works after I reboost my computer!
Thanks a lot!

@parlstrand
Try to reboost your computer and try again.

@peterjc123 @AlbertHuyb Yes it works now :) If anyone has the same problem, you need to restart/reboot your computer after adding intel-openmp to your PATH. I only did it after installing VC Redist 2017, which caused the problem.

That intel-openmp is needed should really be shown on pytorch.org
Even dependencies app doesn't show that these dlls are required for _C.*.pyd

@peterjc123 Thanks! This worked for me too!
My computer has WIn 10,Python 3.5,VS 2017,CUDA 9.0,CUDNN 7.

as for me, everything is ok when using numpy with mkl to replace numpy without mkl. you can try

I have installed pytorch using conda install -c peterjc123 pytorch-cpu
and getting the below error:

C:\ProgramData\Anaconda3\envs\fastai-cpu\lib\site-packages\torch__init__.py in ()
74 pass
75
---> 76 from torch._C import *
77
78 __all__ += [name for name in dir(_C)

ImportError: DLL load failed: The specified module could not be found.

Can anyone please help how to resolve this?

@khemanivishal Could you please try the solutions introduced before in this post? And you can try the official package instead.

I have installed pytorch 0.4.0, cuda 9.1, pip version on windows 10. After the installation I am having this error when I try to import.
from torch._C import *
ImportError: DLL load failed: The operating system cannot run %1.
Where does the problem resides. I did download the wheel that is in the official web site.
I have Nvidia cuda 5.0 capability graphic card.

@we-l-ee Your problem is that some components of your Python env is 32-bit. Please install 64-bit Python and numpy.

@peterjc123 Thank you for the reply. I am using 64-bit Python and re-install the numpy 64-bit version. However I still get the same error.

@we-l-ee You can use something like Dependencies to detect the problems for you. Let it open Python dir/Lib/site-packages/torch/_C.pyd and show me some hints.

@peterjc123
capture

@we-l-ee I cannot see anything from this. Could you try Anaconda?

"conda install -c peterjc123 pytorch-cpu" worked for me! Many thanks guys!

@peterjc123 , I tried the suggestions posted earlier as asked by you, still getting the same error
I tried conda install -c peterjc123 vc vs2017_runtime, still did not resolve the issue
where conda shows:
C:\ProgramData\Anaconda3Library\binconda.bat
C:\ProgramData\Anaconda3\Scriptsconda.exe

where python shows:
C:\ProgramData\Anaconda3\envs\fastai-cpupython.exe
C:\ProgramData\Anaconda3python.exe

Tried dependency walker for _C.cp36-win_amd64.pyd. Attached the screenshot for it
screenshot

Can you please check the image once and let me know if I am missing anything.

@khemanivishal Could you please try the official package on http://pytorch.org?

@we-l-ee You can try to run in Anaconda Prompt. I guess your PATH variable is polluted and some dependencies don't load correctly.

@AlbertHuyb @we-l-ee I solved this problem by follow step:
pip3 uninstall numpy
pip3 install numpy-1.14.3+mkl-cp36-cp36m-win_amd64.whl (download from http://www.lfd.uci.edu/~gohlke/pythonlibs)

Same issure here except it's line 78.
Clean installation of python 3.6, Installed using the pip command suggested by the official website. Restarted, installed VC2017 and intel openmp but the problem persists.

@atlantisq What is your OS (using winver)? And you can use Dependencies to detect the potential problem there. See here.

@peterjc123 Windows 10 ver 1709, build 16299.431. Is Dependencies a Windows tool or a standalone program?

@atlantisq It is a standalone project listed here. And your problem seems to be similar with #7458.

@peterjc123 I installed miniconda and installed torch from there along with several other packages. When I try to import torch it says torch isn't there. Then installed torch again from pip and now it works. Thanks for the input!

Problem can be reproduced if I uninstall miniconda, so it must be one of the packages is missing.

@atlantisq The problem may be on the VC Redist side. Try if that works if you put the files of peterjc123/vs2017_runtime on Anaconda Cloud into PATH.

@peterjc123 Already solved by installing mkl_fft with pip. Pip also installed icc-rt, intel-numpy, intel-openmp, mkl, mkl-fft, mkl-random at the same time, so it must be some or all of these packages missing. It works now; thanks a lot for the assistance.

@kingstarcraft I fixed this problem by installing numpy-mkl. Thanks!

@SpartaG177
F:\DocumentsOnF\CodingData\Python>pip install numpy-mkl
Collecting numpy-mkl
Could not find a version that satisfies the requirement numpy-mkl (from versions: )
No matching distribution found for numpy-mkl

I am on Win10 and these 'solutions' seem like a lot of guessing. I get
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [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 "", line 1, in
File "C:\Users\dae\AppData\Local\Programs\Python\Python36\lib\site-packages\torch__init__.py", line 78, in
from torch._C import *
ImportError: DLL load failed: The specified module could not be found.

@soumith do we have a list of packages we had in the env when we built the windows packages? looks like we might need to list them as part of the install instructions

@apaszke @soumith Well, the problem is called dll hell on Windows. Presently, it mostly lies on openmp, vs2017 and numpy. For the two first two, next time we can pack them into the package for wheels. But for numpy, because we built it with MKL, so we need numpy-mkl. However, numpy or numpy-mkl is not on official pypi server for Windows. So we may should write this into the install instructions.

Had the same issue, tried to reinstall both the VC2017 redist and CUDA 9.1 multiple times, to no avail. But installing numpy-mkl did the trick. This requirement should really be in the docs IMO (as the Windows FAQ insists this issue is one with VC2017), or perhaps more granularity when an dll import fails? (not sure if that's actually possible).

to be fair, I'm not doing this in a conda environment - installed torch through pip. but would love some more info on explicitly what other binaries are required (be it CUDA, cuDNN, numpy-mkl, intel-openmp, etc.)

In particular, the process for me to get import torch to work was:

  1. Install Visual Studio Community 2017
  2. Install VC2017 Redist.
  3. Install CUDA 9.1
    NOTE: In this, the installation of Visual Studio Integration failed, likely due to an issue discussed here:
  4. Install cuDNN 7.1.
  5. Install numpy-mkl via pip3 and the wheel provided here.
  6. pip3 install torch for CUDA 9.1 via the official website.

Notably, I didn't explicitly install intel-openmp, and I didn't install CUDA Visual Studio integration, but I'm able to successfully import torch. @peterjc123 any intuition for why this might be? Trying to avoid running into more subtle issues later, and above it's implied that intel-openmp is necessary, and in your (potentially deprecated) setup instructions pre-0.4 here, it's implied that Visual Studio integration is necessary.

@roozmahdavian Yes, we will fix the doc. But it is very hard for us to detect what's wrong there using existing python libraries. Luckily, there is an external tool that does the work there called Dependencies.
As for the instructions on my repo, it applies to CI packages only, which doesn't pack CUDA Visual Studio integration(NVTX) in. And actually, intel-openmp is included in numpy+mkl, so you don't need to explicitly install it. But for those with only numpy, it is needed.
And finally, wheel support for Windows is rather new. So there are problems emerging. I think it will get better when you post issues that help us improve it.

@akhadangi - this solved my issue too.

Thanks,
Shivam

@roozmahdavian you helped fix my issues! I am on a virtualenv with pip on windows 10 64 (no conda or Anaconda). Had to delete numpy (it didn't want to uninstall), install numpy-MKL from your link then import torch worked.

I have below issue as well. Windows 7 (CPU only).

>>> import torch
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\mycp2fky\AppData\Local\Continuum\anaconda3\envs\pytorch\lib\site-packages\torch\__init__.py", line 76, in <module>
    from torch._C import *
ImportError: DLL load failed: The specified module could not be found.

I have fixed it using below command from @peterjc123 . Thanks a lot..

conda install -c peterjc123 pytorch-cpu

I fixed the issue with this command:

conda install -c peterjc123 pytorch-cpu

Pd: I'm trying the insfrastucture on a non-gpu windows 7 enviroment

@gulstein86 @fmcalcagno Is the official one not working? Could you please try conda install -c pytorch pytorch-cpu? The package hosted in my Anaconda Cloud is 0.3.1, but the official one is 0.4.0.

Here is my report of this issue. Hopefully it could help to give you some hints on how to deal with it.
https://gist.github.com/peterjc123/6b804651288e76db7b5fabe5348e1f03

@peterjc123
I had ImportError: DLL load failed: The operating system cannot run %1.
I fixed it by installing numpy-1.14.3+mkl (thanks to @kingstarcraft ), I downloaded it from: http://www.lfd.uci.edu/~gohlke/pythonlibs
I don't have Anaconda but simple Python 3.6, so installation looks like:
pip3 install numpy-1.14.3+mkl-cp36-cp36m-win_amd64.whl

@soumith Fixed by #7979. Should we close this?

I meet the same error using pip to install Pytorch 0.4 on Python 3.6.5 without GPU support, Windows10.
Here is my solution:

  1. Download win-64/intel-openmp-2018.0.0-8.tar.bz2
  2. unzip the downloaded file, and put the dll files in Library\bin into Python dll path: C:\Users\username\AppData\Local\Programs\Python\Python36\DLLs(you can locate python path using where python command)
  3. check if Python path in environment variables
  4. open another console and try

this worked for me~👏

Getting the same issue;

(python35) E:\Development>conda info

     active environment : python35
    active env location : C:\Users\uqasnosw\AppData\Local\Continuum\Miniconda3\envs\python35
            shell level : 1
       user config file : C:\Users\uqasnosw\.condarc
 populated config files : C:\Users\uqasnosw\.condarc
          conda version : 4.5.4
    conda-build version : not installed
         python version : 3.6.1.final.0
       base environment : C:\Users\uqasnosw\AppData\Local\Continuum\Miniconda3  (writable)
           channel URLs : https://conda.anaconda.org/conda-forge/win-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://repo.anaconda.com/pkgs/main/win-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/free/win-64
                          https://repo.anaconda.com/pkgs/free/noarch
                          https://repo.anaconda.com/pkgs/r/win-64
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://repo.anaconda.com/pkgs/pro/win-64
                          https://repo.anaconda.com/pkgs/pro/noarch
                          https://repo.anaconda.com/pkgs/msys2/win-64
                          https://repo.anaconda.com/pkgs/msys2/noarch
          package cache : C:\Users\uqasnosw\AppData\Local\Continuum\Miniconda3\pkgs
                          C:\Users\uqasnosw\AppData\Local\conda\conda\pkgs
       envs directories : C:\Users\uqasnosw\AppData\Local\Continuum\Miniconda3\envs
                          C:\Users\uqasnosw\AppData\Local\conda\conda\envs
                          C:\Users\uqasnosw\.conda\envs
               platform : win-64
             user-agent : conda/4.5.4 requests/2.14.2 CPython/3.6.1 Windows/10 Windows/10.0.16299
          administrator : False
             netrc file : None
           offline mode : False


(python35) E:\Development>python
Python 3.5.5 | packaged by conda-forge | (default, Feb 13 2018, 06:15:35) [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\uqasnosw\AppData\Local\Continuum\Miniconda3\envs\python35\lib\site-packages\torch\__init__.py", line 78, in <module>
    from torch._C import *
ImportError: DLL load failed: The operating system cannot run %1.

The instructions by @lutein didn't fix it for me, and I noticed that the PR #7979 has been rolled-back. Is there a known workaround for this problem?

@aaronmarkham #7979 has not been rolled-back in the master branch. It is just an internal branch of @ezyang that tried to revert it back. Your problem is already stated in the doc, so I won't talk about it again.

@peterjc123 Thanks for the quick reply and clarification! Indeed, I followed the instructions at this link and running conda install mkl mkl_fft intel-openmp numpy (note the underscore, not dash in mkl_fft) fixed this for me. Please disregard my comment above.

Thank you, looking forward to learning torch.

Hi everybody, in my case the solution was to install the precompiled numpy package from here: https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy

My Setup:
Windows 10
python 3.6.5/pip3 - NOT CONDA
No GPU support

My Steps to a locally installed working copy of PyTorch:
Download and Installed python 3.6.5 from https://www.python.org/downloads/release/python-365/ (I chose 64bit)
Visited https://pytorch.org/#pip-install-pytorch , selected pip, windows, python 3.6.5, from this it told me to run the following commands:

pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.0-cp36-cp36m-win_amd64.whl 
pip3 install torchvision

During this process, it downloaded numpy (from pip, and this caused the issue for me)
pip3 uninstall numpy
Visit https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy and select a package (I selected numpy‑1.14.5+mkl‑cp36‑cp36m‑win_amd64.whl)
Install using pip3 and where ever the downloaded whl file is (EG)
pip3 install ./Downloads/numpy‑1.14.5+mkl‑cp36‑cp36m‑win_amd64.whl

Test import torch again.
Send me cookies.

Sorry to interrupt this conversation here but here's a 100% working and fastest fix for non-conda installs too (ie torch installed via pip):
Download intel-openmp from https://anaconda.org/anaconda/intel-openmp/files
unpack it and append the bin folder to your PATH

;)

@harlyh can you elaborate more about the second step? I've tried the openmp but that didn't work for me.

When you unpack the intel-openmp zip you will get 3 folders, one of them is called bin.
Append full path of that bin folder to your environment variable called PATH
After that when you run command prompt (start -> run -> cmd) and use either env or set commands you should see the path to that bin folder in the PATH=.... variable

how to solve this?
I cannot import torch in python.

In [1]: import torch

ImportError Traceback (most recent call last)
in ()
----> 1 import torch

~\Anaconda3\lib\site-packages\torch__init__.py in ()
74 pass
75
---> 76 from torch._C import *
77
78 _all_ += [name for name in dir(_C)

ImportError: DLL load failed: The specified module could not be found.

@AnirbanKisku please look at the solutions presented in this thread. Specifically, look at the conversation bits starting at https://github.com/pytorch/pytorch/issues/4518#issuecomment-384195186.
Im positive you might be experiencing the same issue, but you did not provide much information.

python preprocess.py -train_src data/src-train.txt -train_tgt data/tgt-train.txt -valid_src data/src-val.txt -valid_tgt data/tgt-val.txt -save_data data/demo
Traceback (most recent call last):
File "preprocess.py", line 12, in
import torch
File "C:\Users\mramkuma\AppData\Local\Programs\Python\Python35\lib\site-packages\torch__init__.py", line 78, in
from torch._C import *
ImportError: DLL load failed: The specified module could not be found.

what to do bro?

Install numpy-1.15 mkl https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy works for me on Windows 10 x64, Python 3.6, CUDA 9.0.

This seems to have worked for me:
Uninstalled pytorch and pytorch-cpu
Install pytorch-cpu conda install -c peterjc123 pytorch-cpu
If that does not work, uninstall pytorch(es) and:

I got the same error, solved in three steps
1) pip uninstall torch
2) conda install -c peterjc123 vc
3) conda install -c peterjc123 pytorch-cpu

thanks peter!

With the environment ( I have build this environment with miniconda) :

  • OS = windows 10 1809
  • python =3.7
  • numpy = 1.15.4

the import error will happens, no matter import numpy or import torch.

But when I downgrade the python version to 3.6.7(numpy=1.15.4), the error disappeared. It seems weird.

@Whisht If you update to python 3.7, what version of numpy does it install? What will happen if you update numpy to 1.15?

@peterjc123 Yes, the numpy version is 1.15.4

@Whisht This looks like a Numpy issue. Please open a issue here. I guess they may be using a different MKL version. Or some dependencies are messed up in the conda environment during the installation.

I got the same error, solved in three steps

  1. pip uninstall torch
  2. conda install -c peterjc123 vc
  3. conda install -c peterjc123 pytorch-cpu

thanks peter!

These steps worked for me on windows 10. Thank you.

I am using python 2.7 of my mac system (not third party python)
I faced this problem and got a solution
simply run this command, make sure to adapt it to your environment 👍

sudo install_name_tool -change @rpath/libc++.1.dylib /usr/lib/libc++.1.dylib /Library/Python/2.7/site-packages/torch/_C.so

With the environment ( I have build this environment with anaconda) :
OS = windows 10
python =3.6
cuda = 9.0
Pytorch = 1.0.1

error: from torch._C import * (ImportError: DLL load failed: The specified module could not be found!!!
So, I use this solution:conda install -c defaults intel-openmp -f

Although this problem is solved, the version of Pytorch is changed to 0.4.1!!!

can you help me use Pytorch1.0 without ImportError? @peterjc123?

After switching to pytorch 1.0.1 with cuda 10 and python 3.7 (Windows 10 & Anaconda 1.9.6 virtual env) I also get this error:

from torch._C import *
ImportError: DLL load failed

same for fresh virtualenv with python 3.6

In C:\Users\Name.conda\envspython37\Lib\site-packages\torch there is only a file named _C.cp37-win_amd64.pyd

With cuda 9.0 everything was running fine.

Also, same problem with only "conda install pytorch-cpu torchvision-cpu -c pytorch". So it's not cuda- or cudnn-related i guess.

Btw I tried all this stuff: It didn't work for me. And I can't use an old peterjc123/win-64::pytorch-cpu-0.3.1-py36_cpuhe774522_2 version. I need pytorch 1.0.1 with cuda support.

I met this problem today after upgrading to python 3.7.2. Didn't work even after recompile. Worked around by returning to python 3.7.1.

conda install python==3.7.1

This also worked for me.
Same for python 3.6: Using newest python 3.6.8 gives the same error
conda install python==3.6.7 works

@HarryHHung @djdookie I reproduced this issue and analyzed the possible reason. It seems that the previous way (editing PATH) of overriding the dll loading dirs is not working anymore. For better visibility, I've opened a new issue: https://github.com/pytorch/pytorch/issues/17051

@peterjc123 Good finding. Thanks for your effort!

I don't know how to solve error: from torch._C import * (ImportError: DLL load failed: The specified module could not be found with Pytorch1.0. Can you help me?@djdookie

In my environment(win8.1, python3.7.1, Pytorch1.0.1), this error occurred in virtual env(used anaconda) but didn't occur in root(base) env.
According to my verification, in my case, this error didn't occur when virtual env was created by prompt(not by anaconda navigator).
I hope this will help someone.

Switching to Python 3.7.1 from 3.7.2 worked for me. So appears to be a version conflict issue.

conda install python==3.6.7
worked for me. I think it was 3.6.8 before this.

Thanks for all the help.

Hey everyone I just wanted to share the solution that worked for me to install pytorch1.0.0 using conda4.6.4 on a windows 10 machine with no GPU since it took me so long to figure out.
I think the biggest issue was not using python 3.6.7 for me.

repeat these steps:
conda create -n myEnv python=3.6.7
conda install pytorch-cpu=1.0.0 -c pytorch

Hey everyone, I have also encountered the same problem and solved it by making full Conda env including anaconda and then installed pytorch with cuda(for gpu support)
and it worked for me.

Here is my answer on stackoverflow: https://stackoverflow.com/a/54742569/9071644

For people who can't wait to stay at the cutting edge (like me), there are two ways to go. Either recompile with the most updated pytorch source which thanks to @peterjc123. Or upgrade to the most recent python build from channel c3i_test.

conda install -c c3i_test python

I can confirm that package python-3.7.2 build h8c8aaf0_6 solved the problem. https://github.com/ContinuumIO/anaconda-issues/issues/10640

Update: A python fix build has been released to the default channel. We can now upgrade with the following command to solve this issue.

conda update python

I am also getting the error
import torch File "C:\Users\dilee\Anaconda3\lib\site-packages\torch\__init__.py", line 76, in <module> from torch._C import * ImportError: DLL load failed: The specified module could not be found.

can someone help me out to resolve this error

resolved

How do you solved it?

window 10
python3.6
use pip and conda none to install pytorch,and do not use the anaconda.
now i cannot solve the error
File "", line 1, in
File "D:\Python36\lib\site-packages\torch__init__.py", line 102, in
from torch._C import *
ImportError: DLL load failed: 找不到指定的程序。

@helenwyw Please update your python if you are using Python 3.6.0.

@peterjc123 Is it the version problem?Which version is recommended?thankyou

3.6.X (X>0) is supported. I recommend 3.6.7 because it's tested in CI.

oh,i'll try. thank you!

@peterjc123 hhh , it's ok 😄

@peterjc123 Hello!I also meet the same problem.
windows 10 Anaconda python3.6.3
conda install pytorch-cpu torchvision-cpu -c pytorch
I tried the solution :conda install -c peterjc123 pytorch-cpu,it works.
BUT! The version of pytorch is 0.3.1 , it is not meet my needs. I suggest you could explain the version of pytorch.
I uninstall it, and reinstall by conda install pytorch-cpu torchvision-cpu c pytorch.
I tried several method this page mentioned.
Finally, this sloution works!
Download win-64/intel-openmp-2018.0.0-8.tar.bz2 and put the dll files in Library\bin into a dir and append the path of it to the environment variable PATH.
And reboot the windows!
Thank you!

Same found problem on Windows 10 ( _ImportError: DLL load failed: The specified module could not be found._ )
im installing with this conda install pytorch-cpu torchvision-cpu -c pytorch
actually forget about my previous version of python ( around 3.6.X) , but im updated my python to 3.6.8 and it solve the problem.

Had the same issue on mac after upgrading. conda install pytorch=1.0.0 -c pytorch fixed the issue for me.

@nshervt This issue is tracking a Windows specific issue. If you have trouble installing PyTorch 1.1 from binary distributions on OS X, please file a new bug. Thanks!

On MacOS Mojave I am getting

---> 79 from torch._C import *

ImportError: dlopen(/usr/local/lib/python3.6/site-packages/torch/_C.cpython-36m-darwin.so, 9): Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib
  Referenced from: /usr/local/lib/python3.6/site-packages/torch/lib/libshm.dylib
  Reason: image not found

There is a bug in torch version 1.1.0. Install 1.0.0 for MacOS.

pip3 install torch==1.0.0 torchvision==0.2.2.post3

This will solve the problem.

Not sure if anyone has solved this issue but windows 10, Python 3.7.1 installing from Spyder using the !pip install. CUDA was messing up that error message for me. So i deleted the files manually( uninstall) took forever and reinstalled the non-cuda version. Works fine now.

I had the same problem on python: 3.7.3, cuda 10.1, pythorch 1.2.
For me uninstalling the package and installing 1.0.0 version with conda solved the problem:

conda install pytorch=1.0.0 -c pytorch
conda install -c pytorch torchvision

I installed Python version 3.6.8 and it solved my problem

I had the same error, i simply changed the environment in Anaconda from base to myenv that i had compatiple pytorch there. I assume one should install the right version of Pytorch

I had the same problem on windows 10 after installing with pip3 with python 3.7.4 and CUDA version 10.1. (My cuda driver is this version: NVIDIA CUDA 10.1.0 driver). But on an import the same error that others had.

To fix it i did the following; pip3 uninstall torch and reinstall with CUDA 9.2. The import goes fine now (torch.cuda.is_available is true, so everything is working). Hope this helps someone.

use torch 1.1.0, I think it was torch 1.3.0 before this.

@HarshneetBhatia Which version are you using? Do you have CUDA cards? How did you install it?

Hi !
Can i simple run the following code
pip3 install torch===1.3.0 torchvision===0.4.1 -f https://download.pytorch.org/whl/torch_stable.html
without setting up my CUDA on the machine ?

and yes i have GTX 1660 ti on my machine.

Thanks in advance :)

I get a similar error in the following context: Perviously, I successfully used windows10 pytorch 0.2.1 (using the anaconda distribution from -c peterjc123). We have now downloaded a pip .whl for all of us to use and so I uninstalled pytorch 0.2.1 and tried installing the wheel file using

pip install $PATH_TO_WHL$/torch-0.3.0b0+591e73e-cp36-cp36m-win_amd64.whl

This completes successfully, but then I get (in spyder, PyDev and python command line):
'>> import torch
Traceback (most recent call last):
File "C:\Users\alexandre\Anaconda3\lib\site-packages\torch__init__.py", line 76, in
from torch._C import *
ImportError: DLL load failed: The specified module could not be found.
'

I am on windows 10, python 3.6.4, conda 4.4.10. And pip is the anaconda pip.

As a fallback I tried:
conda install -c peterjc123 pytorch cuda80
and that 'worked'

But I am curious why the .whl file fails for me (it works on a colleague's machine).

This works 👍

I had the same problem of getting error "from torch._C import * ImportError: DLL load failed: The specified module could not be found."

Using Windows - Pure Python 3.6 - torch 0.4.0 - Virtual Environment

I solved it with the following steps:

  1. Ensure that you have version 9.0.1 of pip: python -m pip install pip==9.0.1
  2. pip install mkl intel-openmp
  3. Add to system path: {path to virtualenv}Library\bin
  4. pip install torch==0.4.0 -f https://download.pytorch.org/whl/torch_stable.html

conda update python works well. The updated python version is 3.8.1

The combination that worked for me for a complete offline installation:
CUDA 10.1 (with the matching cuDNN library)
Python 3.6.10 (Anaconda)
pyYAML 5.1 (from PyPI)
torch 1.4.0 cuda101 (from Anaconda Cloud)
torchvision 0.5.0 (from PyPi)

Note that I have installed the VS requirements beforehand

This should be the msvc problem. Please download the whl file from https://pypi.org/project/msvc-runtime/ and install it.
My config:
Windows 10
cudatoolkit 10.0.130
pytorch 1.2.0
msvc-runtime 14.26.28720

I installed Python version 3.6.8 and it solved my problem

Do pytorch support python 3.7? My python version is 3.7.x and it can't solved my problem

Sorry, I'm not sure whether it could work. While the version of python is 3.7.4 in my another computer and it does not have the problem. Maybe you can have a try.

------------------ 原始邮件 ------------------
发件人: "liaoxuewei"<[email protected]>;
发送时间: 2020年8月20日(星期四) 上午10:44
收件人: "pytorch/pytorch"<[email protected]>;
抄送: "倪思琪"<[email protected]>; "Comment"<[email protected]>;
主题: Re: [pytorch/pytorch] from torch._C import * (ImportError: DLL load failed: The specified module could not be found. (#4518)

I installed Python version 3.6.8 and it solved my problem

Do pytorch support python 3.7? My python version is 3.7.x and it can't solved my problem


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.

I solved this problem by installing gpu driver. https://www.nvidia.cn/Download/index.aspx
You should check if the GTX driver is installed.

This should be the msvc problem. Please download the whl file from https://pypi.org/project/msvc-runtime/ and install it.
My config:
Windows 10
cudatoolkit 10.0.130
pytorch 1.2.0
msvc-runtime 14.26.28720

This worked with following config,
Windows 10
cudatoolkit 10.0.130
pytorch 1.4.0
msvc-runtime

Thanks for the pypi package!

Was this page helpful?
0 / 5 - 0 ratings