导入open_clip时出现ModuleNotFoundError

问题描述 投票:0回答:3

导入 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,但不知道为什么我无法使用该库。

python clip modulenotfounderror
3个回答
5
投票

OpenClip 是一个单独的模块。您必须单独安装它。

pip install open_clip_torch

之后事情应该按预期进行。


2
投票

您需要运行

setup.py
文件:

这是安装顺序:

  1. 使用
    pip
  2. 安装
pip3 install open_clip_torch
  1. 查找包的文件夹(python脚本)
# 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__)

导航到模块的文件夹

  1. 找到
    setup.py
    。然后跑。
python3 setup.py install

文档


编辑

请参阅此链接

来自 ModuleNotFoundError:没有名为“torch._C”的模块


0
投票

我也有同样的问题。事实证明这是由于 torch 和 open_clip_torch 版本不匹配造成的。我有 torch 1.12 和 open_clip_torch 2.23。我将 open_clip_torch 降级到 2.18 并且成功了!

© www.soinside.com 2019 - 2024. All rights reserved.