我打开了一个 Jupyter 笔记本,我尝试运行这一行:import torch
。结果是这个堆栈跟踪:
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-3-eb42ca6e4af3> in <module>
----> 1 import torch
~/.local/lib/python3.6/site-packages/torch/__init__.py in <module>
187 # See Note [Global dependencies]
188 if USE_GLOBAL_DEPS:
--> 189 _load_global_deps()
190 from torch._C import *
191
~/.local/lib/python3.6/site-packages/torch/__init__.py in _load_global_deps()
140 lib_path = os.path.join(os.path.dirname(here), 'lib', lib_name)
141
--> 142 ctypes.CDLL(lib_path, mode=ctypes.RTLD_GLOBAL)
143
144
/usr/lib/python3.6/ctypes/__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
346
347 if handle is None:
--> 348 self._handle = _dlopen(self._name, mode)
349 else:
350 self._handle = handle
OSError: /home/xianx/.local/lib/python3.6/site-packages/torch/lib/libtorch_global_deps.so: cannot open shared object file: No such file or directory
我尝试以这种方式导入pytorch:
xianx@25b6c9724ef7452b9fc3211ab99037e9-master-0:~$ pip install torch
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: torch in /usr/local/lib/python3.6/dist-packages (1.2.0)
Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from torch) (1.18.1)
我确实找到了 this answer,但他们使用旧版本的 torch 和 numpy 解决了这个问题。如果可能,我更愿意使用最新版本。