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.

2

3 Answers

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

pip install open_clip_torch 

After that things should work as one expects.

1

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'

2

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!

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like