ImportError: DLL load failed while importing _C: Das angegebene Modul wurde nicht gefunden./The specified module can not be found

nimajneb: <p>Hi everyone,<br>
Ive just installed torch and torchvision on my anaconda shell:</p>
<h1><a name="p-466900-packages-in-environment-at-cusersbenjaanaconda3-1" class="anchor" href="#p-466900-packages-in-environment-at-cusersbenjaanaconda3-1"></a>packages in environment at C:\Users\benja\anaconda3:</h1>
<h1><a name="p-466900-h-2" class="anchor" href="#p-466900-h-2"></a></h1>
<h1><a name="p-466900-name-version-build-channel-3" class="anchor" href="#p-466900-name-version-build-channel-3"></a>Name                    Version                   Build  Channel</h1>
<p>pytorch                   2.5.1              py3.11_cpu_0    pytorch<br>
pytorch-mutex             1.0                         cpu    pytorch</p>
<h1><a name="p-466900-packages-in-environment-at-cusersbenjaanaconda3-4" class="anchor" href="#p-466900-packages-in-environment-at-cusersbenjaanaconda3-4"></a>packages in environment at C:\Users\benja\anaconda3:</h1>
<h1><a name="p-466900-h-5" class="anchor" href="#p-466900-h-5"></a></h1>
<h1><a name="p-466900-name-version-build-channel-6" class="anchor" href="#p-466900-name-version-build-channel-6"></a>Name                    Version                   Build  Channel</h1>
<p>torchvision               0.20.1                py311_cpu    pytorch</p>
<p>However, when I am trying import torch and torchvision, the following message is displayed:</p>
<hr>
<p>ImportError                               Traceback (most recent call last)<br>
Cell In[7], line 3<br>
1 import inspect<br>
2 import torch<br>
----&gt; 3 import torchvision<br>
4 from torch import nn<br>
5 from torch import optim</p>
<p>File ~\anaconda3\Lib\site-packages\torchvision_<em>init</em>_.py:9<br>
5 import torch<br>
7 # Don’t re-order these, we need to load the _C extension (done when importing<br>
8 # .extensions) before entering _meta_registrations.<br>
----&gt; 9 from .extension import _HAS_OPS  # usort:skip<br>
10 from torchvision import _meta_registrations, datasets, io, models, ops, transforms, utils  # usort:skip<br>
12 try:</p>
<p>File ~\anaconda3\Lib\site-packages\torchvision\extension.py:6<br>
2 import sys<br>
4 import torch<br>
----&gt; 6 from ._internally_replaced_utils import _get_extension_path<br>
9 _HAS_OPS = False<br>
12 def _has_ops():</p>
<p>File ~\anaconda3\Lib\site-packages\torchvision_internally_replaced_utils.py:4<br>
1 import importlib.machinery<br>
2 import os<br>
----&gt; 4 from torch.hub import _get_torch_home<br>
7 _HOME = os.path.join(_get_torch_home(), “datasets”, “vision”)<br>
8 _USE_SHARDED_DATASETS = False</p>
<p>File ~\anaconda3\Lib\site-packages\torch\hub.py:22<br>
19 from urllib.request import Request, urlopen<br>
21 import torch<br>
—&gt; 22 from torch.serialization import MAP_LOCATION<br>
25 class _Faketqdm:  # type: ignore[no-redef]<br>
26     def <strong>init</strong>(self, total=None, disable=False, unit=None, *args, **kwargs):</p>
<p>File ~\anaconda3\Lib\site-packages\torch\serialization.py:35<br>
33 import torch<br>
34 import torch._weights_only_unpickler as _weights_only_unpickler<br>
—&gt; 35 from torch._sources import get_source_lines_and_file<br>
36 from torch._utils import _import_dotted_name<br>
37 from torch.storage import _get_dtype_from_pickle_storage_type</p>
<p>File ~\anaconda3\Lib\site-packages\torch_sources.py:8<br>
5 from textwrap import dedent<br>
6 from typing import Any, List, NamedTuple, Optional, Tuple<br>
----&gt; 8 from torch._C import ErrorReport<br>
9 from torch._C._jit_tree_views import SourceRangeFactory<br>
12 def get_source_lines_and_file(<br>
13     obj: Any,<br>
14     error_msg: Optional[str] = None,<br>
15 ) → Tuple[List[str], int, Optional[str]]:</p>
<p>ImportError: DLL load failed while importing _C: Das angegebene Modul wurde nicht gefunden.</p>
<p>How to solve this issue?</p>

ptrblck: <p>Not reproducible by installing <code>2.5.1+cpu</code> from <code>conda</code>:</p>
<pre data-code-wrap="python"><code class="lang-python">conda install pytorch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 cpuonly -c pytorch
...
The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    brotli-python-1.0.9        |  py311h6a678d5_9         356 KB
    certifi-2025.1.31          |  py311h06a4308_0         163 KB
    filelock-3.13.1            |  py311h06a4308_0          24 KB
    gmpy2-2.2.1                |  py311h5eee18b_0         248 KB
    idna-3.7                   |  py311h06a4308_0         133 KB
    jinja2-3.1.5               |  py311h06a4308_0         358 KB
    markupsafe-3.0.2           |  py311h5eee18b_0          27 KB
    mkl-service-2.4.0          |  py311h5eee18b_2          69 KB
    mkl_fft-1.3.11             |  py311h5eee18b_0         207 KB
    mkl_random-1.2.8           |  py311ha02d727_0         328 KB
    mpmath-1.3.0               |  py311h06a4308_0         1.0 MB
    networkx-3.4.2             |  py311h06a4308_0         3.1 MB
    numpy-2.0.1                |  py311h08b1b3b_1          11 KB
    numpy-base-2.0.1           |  py311hf175353_1         9.1 MB
    pillow-11.1.0              |  py311hcea889d_0         973 KB
    pysocks-1.7.1              |  py311h06a4308_0          35 KB
    pytorch-2.5.1              |     py3.11_cpu_0        92.0 MB  pytorch
    pyyaml-6.0.2               |  py311h5eee18b_0         223 KB
    requests-2.32.3            |  py311h06a4308_1         126 KB
    sympy-1.13.3               |  py311h06a4308_1        15.4 MB
    torchaudio-2.5.1           |        py311_cpu         5.1 MB  pytorch
    torchvision-0.20.1         |        py311_cpu         7.1 MB  pytorch
    typing_extensions-4.12.2   |  py311h06a4308_0          81 KB
    urllib3-2.3.0              |  py311h06a4308_0         241 KB
    ------------------------------------------------------------
                                           Total:       136.4 MB
</code></pre>
<pre data-code-wrap="python"><code class="lang-python">&gt;&gt;&gt; import torch                                                                                                                                                                                                   
&gt;&gt;&gt; import torchvision
&gt;&gt;&gt; torch.__version__                                                                                                                                                                                              
'2.5.1'                                                                                                                                                                                                            
&gt;&gt;&gt; torchvision.__version__                                                                                                                                                                                        
'0.20.1'     
</code></pre>

nimajneb: <aside class="quote no-group" data-username="ptrblck" data-post="2" data-topic="217569">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/48/1823_2.png" class="avatar"> ptrblck:</div>
<blockquote>
<p><code>import torch </code></p>
</blockquote>
</aside>
<p>to clarify, I am working on jupyter with Python 3.11.7. When am trying to import, the kernel dies.</p>