导入 open_clip 时出错, 导入 open_clip 时我总是收到此错误:
Traceback (most recent call last):
File "c:\Users\noahs\Desktop\New folder\test.py", line 1, in <module>
import open_clip
File "C:\Users\noahs\Desktop\New folder\folder\lib\site-packages\open_clip\__init__.py", line 2, in <module>
from .loss import ClipLoss
File "C:\Users\noahs\Desktop\New folder\folder\lib\site-packages\open_clip\loss.py", line 2, in <module>
import torch.distributed.nn
File "C:\Users\noahs\Desktop\New folder\folder\lib\site-packages\torch\distributed\nn\__init__.py", line 1, in <module>
from .api.remote_module import RemoteModule
File "C:\Users\noahs\Desktop\New folder\folder\lib\site-packages\torch\distributed\nn\api\remote_module.py", line 25, in <module>
from torch.distributed.rpc.internal import _internal_rpc_pickler
File "C:\Users\noahs\Desktop\New folder\folder\lib\site-packages\torch\distributed\rpc\internal.py", line 12, in <module>
from torch._C._distributed_rpc import _get_current_rpc_agent
ModuleNotFoundError: No module named 'torch._C._distributed_rpc'; 'torch._C' is not a package
这是我正在运行的代码:
import open_clip
model, _, preprocess = open_clip.create_model_and_transforms('ViT-B-32-quickgelu', pretrained='laion400m_e32')
不知道如何处理这个问题。我已经在不同版本上多次安装了 torch,但不知道为什么我无法使用该库。
您需要运行
setup.py
文件:
这是安装顺序:
pip
pip3 install open_clip_torch
# Import and print the file. The output will be the file's location
# Go to the modules main folder
import open_clip
print(open_clip.__file__)
导航到模块的文件夹
setup.py
。然后跑。python3 setup.py install
编辑
请参阅此链接
我也有同样的问题。事实证明这是由于 torch 和 open_clip_torch 版本不匹配造成的。我有 torch 1.12 和 open_clip_torch 2.23。我将 open_clip_torch 降级到 2.18 并且成功了!