【发布时间】:2019-07-10 07:00:48
【问题描述】:
我使用的是 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
【问题讨论】:
标签: python-3.x anaconda pytorch