[GH-ISSUE #180] AttributeError: module 'clip' has no attribute 'load' #156

Open
opened 2026-10-31 21:11:47 +00:00 by bsakaguchi · 9 comments
Owner

Originally created by @jennasawaf on GitHub (Nov 15, 2021).
Original GitHub issue: https://github.com/openai/CLIP/issues/180

I've been working with CLIP for a few weeks now, but for some reason my code stopped working.

This is the code:

import torch
import clip

device = "cuda" if torch.cuda.is_available() else "cpu"
og_model, preprocess = clip.load('ViT-B/32', device)

then the error I get is the following
Screen Shot 2021-11-15 at 3 24 24 PM
:

I tried testing the same code in a sagemaker notebook on aws and it worked there so I'm starting to think it might be because I'm working on a Mac? please let me know if there's something I can do to get it to work.

Originally created by @jennasawaf on GitHub (Nov 15, 2021). Original GitHub issue: https://github.com/openai/CLIP/issues/180 I've been working with CLIP for a few weeks now, but for some reason my code stopped working. This is the code: import torch import clip device = "cuda" if torch.cuda.is_available() else "cpu" og_model, preprocess = clip.load('ViT-B/32', device) then the error I get is the following <img width="791" alt="Screen Shot 2021-11-15 at 3 24 24 PM" src="https://user-images.githubusercontent.com/26900032/141848881-99559609-815f-4e59-b848-c9d64f3fa593.png"> : I tried testing the same code in a sagemaker notebook on aws and it worked there so I'm starting to think it might be because I'm working on a Mac? please let me know if there's something I can do to get it to work.
Author
Owner

@jongwook commented on GitHub (Nov 16, 2021):

do you have a local directory named clip or a file named clip.py in the same directory?

<!-- gh-comment-id:969662306 --> @jongwook commented on GitHub (Nov 16, 2021): do you have a local directory named `clip` or a file named `clip.py` in the same directory?
Author
Owner

@thandal commented on GitHub (Dec 17, 2021):

I think you need to install 'clip-by-openai', not 'clip':
pip3 install clip-by-openai

<!-- gh-comment-id:996973317 --> @thandal commented on GitHub (Dec 17, 2021): I think you need to install 'clip-by-openai', not 'clip': `pip3 install clip-by-openai`
Author
Owner

@jongwook commented on GitHub (Dec 17, 2021):

I think you need to install 'clip-by-openai', not 'clip': pip3 install clip-by-openai

Please note that clip-by-openai is not managed/endorsed by OpenAI.

I realize the OP might've installed clip from PyPI, which they shouldn't -- if that's the case, uninstall it by pip uninstall clip and follow the instructions in README.md to install CLIP properly.

<!-- gh-comment-id:997080467 --> @jongwook commented on GitHub (Dec 17, 2021): > I think you need to install 'clip-by-openai', not 'clip': `pip3 install clip-by-openai` Please note that `clip-by-openai` is not managed/endorsed by OpenAI. I realize the OP might've installed `clip` from PyPI, which they shouldn't -- if that's the case, uninstall it by `pip uninstall clip` and follow the instructions in [README.md](https://github.com/openai/CLIP#usage) to install CLIP properly.
Author
Owner

@davitpapikyan commented on GitHub (Dec 3, 2022):

Use the latest stable version by installing openai-clip:

pip install openai-clip
<!-- gh-comment-id:1336127548 --> @davitpapikyan commented on GitHub (Dec 3, 2022): Use the latest stable version by installing openai-clip: ``` pip install openai-clip ```
Author
Owner

@hrx20000209 commented on GitHub (Dec 14, 2022):

do you have a local directory named clip or a file named clip.py in the same directory?

wow! thanks!! you figure out what I am looking for!

<!-- gh-comment-id:1350335539 --> @hrx20000209 commented on GitHub (Dec 14, 2022): > do you have a local directory named `clip` or a file named `clip.py` in the same directory? wow! thanks!! you figure out what I am looking for!
Author
Owner

@haodong2000 commented on GitHub (Sep 29, 2023):

@davitpapikyan thx!

<!-- gh-comment-id:1740731227 --> @haodong2000 commented on GitHub (Sep 29, 2023): @davitpapikyan thx!
Author
Owner

@Bilal143260 commented on GitHub (Jan 15, 2024):

pip install git+https://github.com/openai/CLIP.git

<!-- gh-comment-id:1891521011 --> @Bilal143260 commented on GitHub (Jan 15, 2024): pip install git+https://github.com/openai/CLIP.git
Author
Owner

@Riyue120 commented on GitHub (Jan 15, 2024):

I had some problems, but they worked out.

Firstly

pip3 install git+https://github.com/openai/CLIP.git
Looking in indexes: http://mirrors.aliyun.com/pypi/simple
Collecting git+https://github.com/openai/CLIP.git
  Cloning https://github.com/openai/CLIP.git to /tmp/pip-req-build-_f2vfa36
  Running command git clone --filter=blob:none --quiet https://github.com/openai/CLIP.git /tmp/pip-req-build-_f2vfa36
  fatal: unable to access 'https://github.com/openai/CLIP.git/': Failed to connect to github.com port 443: Connection timed out
  error: subprocess-exited-with-error
  
  × git clone --filter=blob:none --quiet https://github.com/openai/CLIP.git /tmp/pip-req-build-_f2vfa36 did not run successfully.
  │ exit code: 128
  ╰─> See above for output.
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× git clone --filter=blob:none --quiet https://github.com/openai/CLIP.git /tmp/pip-req-build-_f2vfa36 did not run successfully.
│ exit code: 128
╰─> See above for output.

then i upgrade the pip,pip install --upgrade pipthen it works.
pip3 install git+https://github.com/openai/CLIP.git --user

Secondly

python clip.py 
Traceback (most recent call last):
  File "clip.py", line 38, in <module>
    clip_embeding = ClipEmbeding()
  File "clip.py", line 10, in __init__
    self.model, self.processor = clip.load("/root/clip/model/ViT-B-32.pt", device=self.device)
AttributeError: module 'clip' has no attribute 'load'

so, i tried the above method, pip install openai-clip, but it does not work.
then, i rename my python file name and the floder name, it works.

  • Previous file directory
/root/clip/:
code model

/root/clip/code:
clip.py  clip.ipynb  data  __pycache__  zore-shoot.py

/root/clip/code/data:
cifar-100-python  cifar-100-python.tar.gz

/root/clip/code/data/cifar-100-python:
file.txt~  meta  test  train

/root/clip/code/__pycache__:
clip.cpython-38.pyc  clip.cpython-39.pyc

/root/clip/model:
ViT-B-32.pt
  • Modified file directory
/root/clip-file/:
code  model

/root/clip-file/code:
clip-code.py  clip.ipynb  data  __pycache__  zore-shoot.py

/root/clip-file/code/data:
cifar-100-python  cifar-100-python.tar.gz

/root/clip-file/code/data/cifar-100-python:
file.txt~  meta  test  train

/root/clip-file/code/__pycache__:
clip.cpython-38.pyc  clip.cpython-39.pyc

/root/clip-file/model:
ViT-B-32.pt

Ending

hope these details can help you.

<!-- gh-comment-id:1891903890 --> @Riyue120 commented on GitHub (Jan 15, 2024): I had some problems, but they worked out. ## Firstly ``` pip3 install git+https://github.com/openai/CLIP.git Looking in indexes: http://mirrors.aliyun.com/pypi/simple Collecting git+https://github.com/openai/CLIP.git Cloning https://github.com/openai/CLIP.git to /tmp/pip-req-build-_f2vfa36 Running command git clone --filter=blob:none --quiet https://github.com/openai/CLIP.git /tmp/pip-req-build-_f2vfa36 fatal: unable to access 'https://github.com/openai/CLIP.git/': Failed to connect to github.com port 443: Connection timed out error: subprocess-exited-with-error × git clone --filter=blob:none --quiet https://github.com/openai/CLIP.git /tmp/pip-req-build-_f2vfa36 did not run successfully. │ exit code: 128 ╰─> See above for output. note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error × git clone --filter=blob:none --quiet https://github.com/openai/CLIP.git /tmp/pip-req-build-_f2vfa36 did not run successfully. │ exit code: 128 ╰─> See above for output. ``` then i upgrade the `pip`,```pip install --upgrade pip```then it works. ```pip3 install git+https://github.com/openai/CLIP.git --user``` ## Secondly ``` python clip.py Traceback (most recent call last): File "clip.py", line 38, in <module> clip_embeding = ClipEmbeding() File "clip.py", line 10, in __init__ self.model, self.processor = clip.load("/root/clip/model/ViT-B-32.pt", device=self.device) AttributeError: module 'clip' has no attribute 'load' ``` so, i tried the above method, `pip install openai-clip`, but it does not work. then, **i rename my python file name and the floder name**, it works. - **Previous file directory** ``` /root/clip/: code model /root/clip/code: clip.py clip.ipynb data __pycache__ zore-shoot.py /root/clip/code/data: cifar-100-python cifar-100-python.tar.gz /root/clip/code/data/cifar-100-python: file.txt~ meta test train /root/clip/code/__pycache__: clip.cpython-38.pyc clip.cpython-39.pyc /root/clip/model: ViT-B-32.pt ``` - **Modified file directory** ``` /root/clip-file/: code model /root/clip-file/code: clip-code.py clip.ipynb data __pycache__ zore-shoot.py /root/clip-file/code/data: cifar-100-python cifar-100-python.tar.gz /root/clip-file/code/data/cifar-100-python: file.txt~ meta test train /root/clip-file/code/__pycache__: clip.cpython-38.pyc clip.cpython-39.pyc /root/clip-file/model: ViT-B-32.pt ``` ## Ending hope these details can help you.
Author
Owner

@zheintzleman commented on GitHub (Jun 10, 2025):

Also make sure you haven't named any local files "clip.py"

<!-- gh-comment-id:2960735512 --> @zheintzleman commented on GitHub (Jun 10, 2025): Also make sure you haven't named any local files "clip.py"
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openai/CLIP#156
No description provided.