Search code examples
pytorch

OSError: [WinError 127] The specified procedure could not be found. Error loading \torch\lib\caffe2_detectron_ops.dll" or one of its dependencies


I am so frustrated with pytorch. This is my 3rd time trying to install pytorch and try to learn it. It still failed to import torch.

I am using anaconda so I installed pytorch using

https://anaconda.org/pytorch/pytorch

conda install -c pytorch pytorch

(forecast) C:\Users\test>conda install -c pytorch pytorch
Collecting package metadata (current_repodata.json): done
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 23.1.0
  latest version: 23.5.0

Please update conda by running

    $ conda update -n base -c defaults conda

Or to minimize the number of packages updated during conda update use

     conda install conda=23.5.0



## Package Plan ##

  environment location: C:\Users\test\miniconda3\envs\forecast

  added / updated specs:
    - pytorch


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    ca-certificates-2023.05.30 |       haa95532_0         120 KB
    certifi-2023.5.7           |   py38haa95532_0         153 KB
    openssl-1.1.1u             |       h2bbff1b_0         5.5 MB
    pytorch-2.0.1              |      py3.8_cpu_0       145.5 MB  pytorch
    pytorch-mutex-1.0          |              cpu           3 KB  pytorch
    sympy-1.11.1               |   py38haa95532_0        11.7 MB
    ------------------------------------------------------------
                                           Total:       163.0 MB

The following NEW packages will be INSTALLED:

  mpmath             pkgs/main/win-64::mpmath-1.2.1-py38haa95532_0
  pytorch-mutex      pytorch/noarch::pytorch-mutex-1.0-cpu
  sympy              pkgs/main/win-64::sympy-1.11.1-py38haa95532_0

The following packages will be UPDATED:

  ca-certificates    conda-forge::ca-certificates-2023.5.7~ --> pkgs/main::ca-certificates-2023.05.30-haa95532_0
  openssl            conda-forge::openssl-1.1.1q-h8ffe710_0 --> pkgs/main::openssl-1.1.1u-h2bbff1b_0
  pytorch            pkgs/main::pytorch-1.12.1-cpu_py38h5e~ --> pytorch::pytorch-2.0.1-py3.8_cpu_0

The following packages will be SUPERSEDED by a higher-priority channel:

  certifi            conda-forge/noarch::certifi-2023.5.7-~ --> pkgs/main/win-64::certifi-2023.5.7-py38haa95532_0

then I got below error, I did try to google it and I didn't find solution which works for me. why pytorch is so difficult to use? anyone can help me? Thanks

import torch

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_36364/4265195184.py in 
----> 1 import torch

c:\Users\test\miniconda3\envs\forecast\lib\site-packages\torch\__init__.py in 
    120                 err = ctypes.WinError(last_error)
    121                 err.strerror += f' Error loading "{dll}" or one of its dependencies.'
--> 122                 raise err
    123             elif res is not None:
    124                 is_loaded = True

OSError: [WinError 127] The specified procedure could not be found. Error loading "c:\Users\test\miniconda3\envs\forecast\lib\site-packages\torch\lib\caffe2_detectron_ops.dll" or one of its dependencies.


Solution

  • You can try to install using pip and you can find the prompt on the torch offfical website. Choose your cuda_version and use pip like this pip3 install torch torchvision torchaudio

    This should work.