Skip to content

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

Closed

Description

@HarshneetBhatia

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.

Activity

  1. peterjc123 commented on Jan 7, 2018

    @peterjc123
    Collaborator

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

  2. peterjc123 commented on Jan 7, 2018

    @peterjc123
    Collaborator

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

  3. HarshneetBhatia commented on Jan 7, 2018

    @HarshneetBhatia
    Author

    @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 ?

  4. peterjc123 commented on Jan 7, 2018

    @peterjc123
    Collaborator

    @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.

  5. maatini commented on Jan 7, 2018

    @maatini

    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.

  6. HarshneetBhatia commented on Jan 7, 2018

    @HarshneetBhatia
    Author

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

    Thanks in advance

  7. maatini commented on Jan 7, 2018

    @maatini

    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.

  8. HarshneetBhatia commented on Jan 7, 2018

    @HarshneetBhatia
    Author

    @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.

  9. ezyang commented on Jan 7, 2018

    @ezyang
    Contributor

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

  10. aviolov commented on Feb 20, 2018

    @aviolov

    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).

  11. peterjc123 commented on Feb 20, 2018

    @peterjc123
    Collaborator

    @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.

  12. aviolov commented on Feb 21, 2018

    @aviolov

    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).

  13. peterjc123 commented on Feb 21, 2018

    @peterjc123
    Collaborator

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

  14. code17lines commented on Feb 22, 2018

    @code17lines

    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
    
  15. 150 remaining items

  16. srilalithaveerubhotla commented on Nov 13, 2019

    @srilalithaveerubhotla

    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 👍

  17. nomisto commented on Jan 23, 2020

    @nomisto

    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
  18. HomeLH commented on Mar 11, 2020

    @HomeLH

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

  19. Terizian commented on May 21, 2020

    @Terizian

    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

  20. caozhenxiang-kouji commented on Jun 3, 2020

    @caozhenxiang-kouji

    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

  21. liaoxuewei commented on Aug 20, 2020

    @liaoxuewei

    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

  22. lixite commented on Aug 20, 2020

    @lixite
  23. wss321 commented on Sep 10, 2020

    @wss321

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

  24. krishnansr commented on Sep 19, 2020

    @krishnansr

    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!

  25. Sanjayvaradha commented on Dec 22, 2020

    @Sanjayvaradha

    @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.

    Hi I am not able import pytorch for cpu version. How to solve this?

  26. juniperfdel commented on Mar 10, 2022

    @juniperfdel

    I had this issue after building pytorch from source on windows and the fix was to place all of the generated libraries from the <install folder>\lib folder into the site-packages\torch\lib folder alongside _C.lib

  27. MarouaneZ1 commented on Sep 25, 2022

    @MarouaneZ1

    i got a similar issue :: ImportError: DLL load failed while importing _C the specified module could not be found while trying to use Detectron2LayoutModel

  28. iamtalhaasghar commented on Apr 15, 2023

    @iamtalhaasghar

    related #17203, #9071

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions