Python 3.x PyTorch DLL加载失败

Python 3.x PyTorch DLL加载失败,python-3.x,anaconda,pytorch,Python 3.x,Anaconda,Pytorch,我使用的是Anaconda320812版本和python 3.6.8版本。我正在尝试安装pytorch,它始终显示以下错误消息 >>> import torch Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\Office\Anaconda3\envs\mainenv\lib\site-packages\torch\__in

我使用的是Anaconda320812版本和python 3.6.8版本。我正在尝试安装pytorch,它始终显示以下错误消息

>>> import torch
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Office\Anaconda3\envs\mainenv\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.
这推荐一个pytorch官方网站。它也给出了这个错误

然后我卸载了它并尝试了以下代码

conda install -c peterjc123 pytorch-cpu
还将给出该错误消息

我再次创建了另一个新的环境来测试useterjc123命令,上面也给出了错误消息

现在我真的受够了。请帮我解决这个错误

这是init.py文件代码

################################################################################
# Load the extension module
################################################################################

# Loading the extension with RTLD_GLOBAL option allows to not link extension
# modules against the _C shared object. Their missing THP symbols will be
# automatically filled by the dynamic loader.
import os as _dl_flags

# if we have numpy, it *must* be imported before the call to setdlopenflags()
# or there is risk that later c modules will segfault when importing numpy
try:
    import numpy as np
except ImportError:
    pass

if platform.system() == 'Windows':
    # first get nvToolsExt PATH
    def get_nvToolsExt_path():
        NVTOOLEXT_HOME = _dl_flags.getenv('NVTOOLSEXT_PATH', 'C:\\Program Files\\NVIDIA Corporation\\NvToolsExt')

        if _dl_flags.path.exists(NVTOOLEXT_HOME):
            return NVTOOLEXT_HOME + '\\bin\\x64\\'
        else:
            return ''

    # then add the path to env
    _dl_flags.environ['PATH'] = _dl_flags.path.dirname(
        __file__) + '\\lib\\;' + get_nvToolsExt_path() + ';' + _dl_flags.environ['PATH']

else:
    # first check if the os package has the required flags
    if not hasattr(_dl_flags, 'RTLD_GLOBAL') or not hasattr(_dl_flags, 'RTLD_LAZY'):
        try:
            # next try if DLFCN exists
            import DLFCN as _dl_flags
        except ImportError:
            # as a last attempt, use compile-time constants
            import torch._dl as _dl_flags

    old_flags = sys.getdlopenflags()
    sys.setdlopenflags(_dl_flags.RTLD_GLOBAL | _dl_flags.RTLD_LAZY)

del _dl_flags

try:
    import torch._nvrtc
except ImportError:
    pass

from torch._C import *

__all__ += [name for name in dir(_C)
            if name[0] != '_' and
            not name.endswith('Base')]

if platform.system() != 'Windows':
    sys.setdlopenflags(old_flags)
    del old_flags
根据
conda安装python==3.6.7可以解决这个问题

更新:此问题已解决

conda update python
conda update python