PyTorch DLL加载失败

时间:2019-02-16 08:06:38

标签: python-3.x anaconda pytorch

我正在使用Anaconda 3 2018 12版本和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.

我在anaconda提示符下尝试了以下命令。

conda install pytorch-cpu torchvision-cpu -c pytorch

这是推荐的pytorch官方网站。也会出现此错误。

然后我将其卸载并尝试以下代码。

conda install -c peterjc123 pytorch-cpu

还给出该错误消息。

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

现在我真的受够了。请帮助我解决此错误。

这是 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

1 个答案:

答案 0 :(得分:0)

根据github conda install python==3.6.7可以解决。

更新:此问题已关闭。

conda update python