Frikallo
Frikallo

Reputation: 91

ModuleNotFoundError When Importing open_clip

error importing open_clip, When importing open_clip I always get this error:

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

heres the code im running:

import open_clip

model, _, preprocess = open_clip.create_model_and_transforms('ViT-B-32-quickgelu', pretrained='laion400m_e32')

Not sure how to handle this. Ive installed torch multiple times on different versions and dont know why I cant use the library.

Upvotes: 7

Views: 22177

Answers (3)

coderxx
coderxx

Reputation: 11

I had the same problem. Turns out it was due to torch and open_clip_torch version mismatch. I had torch 1.12 and open_clip_torch 2.23. I downgraded open_clip_torch to 2.18 and it worked!

Upvotes: 0

Freddy Mcloughlan
Freddy Mcloughlan

Reputation: 4506

You need to run the setup.py file:

This is the order of installation:

  1. Install with pip
pip3 install open_clip_torch
  1. Find folder of package (python script)
# 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__)

Navigate to the module's folder

  1. Find setup.py. And run.
python3 setup.py install

Docs


Edit

See this link

From ModuleNotFoundError: No module named 'torch._C'

Upvotes: 5

Sakib Hasan
Sakib Hasan

Reputation: 487

OpenClip is a separate module. You must install it separately.

pip install open_clip_torch

After that things should work as one expects.

Upvotes: 10

Related Questions