[PR #536] When installing CLIP via pip on Python 3.10+ systems with setuptools … #528

Open
opened 2026-10-31 21:15:45 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/openai/CLIP/pull/536
Author: @Aadi775
Created: 3/22/2026
Status: 🔄 Open

Base: main ← Head: patch-1


📝 Commits (1)

  • 41e8420 When installing CLIP via pip on Python 3.10+ systems with setuptools 71+, the installation fails with: ModuleNotFoundError: No module named 'pkg_resources'

📊 Changes

1 file changed (+3 additions, -4 deletions)

View changed files

📝 setup.py (+3 -4)

📄 Description

…71+, the installation fails with: ModuleNotFoundError: No module named 'pkg_resources'

Problem

When installing CLIP via pip on Python 3.10+ systems with setuptools 71+, the installation fails with:

ModuleNotFoundError: No module named 'pkg_resources'

pip creates an isolated build environment in a temporary directory when building packages from source. In this isolated environment, setuptools is installed fresh — and in newer versions (71+), pkg_resources is no longer automatically available as a top-level importable module within that subprocess context, even though setuptools itself is present.

The original setup.py imported pkg_resources at the module level and used pkg_resources.parse_requirements() to read requirements.txt. Since this code runs inside pip's isolated build subprocess, it fails before the wheel can even be built — making CLIP completely uninstallable from source on modern systems without workarounds.

Closes #532

What Changed

Before:

import pkg_resources

install_requires=[
    str(r)
    for r in pkg_resources.parse_requirements(
        open(os.path.join(os.path.dirname(__file__), "requirements.txt"))
    )
]

After:

install_requires=[
    stripped
    for line in open(os.path.join(os.path.dirname(__file__), "requirements.txt"))
    for stripped in [line.strip()]
    if stripped and not stripped.startswith("#")
],
  • Removed the pkg_resources import entirely
  • Replaced parse_requirements() with plain Python file I/O
  • Strips each line before checking for blank/comment — so lines like " # comment" are correctly excluded (previous version missed these)
  • Properly indented inside install_requires

Impact

  • Fixes installation on any system running setuptools 71+
  • Tested on Python 3.10.19, setuptools 82.0.1
  • No behavior change for existing users
  • Removes the only legacy pkg_resources dependency from setup.py
  • Makes the build process more robust and future-proof

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/openai/CLIP/pull/536 **Author:** [@Aadi775](https://github.com/Aadi775) **Created:** 3/22/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `patch-1` --- ### 📝 Commits (1) - [`41e8420`](https://github.com/openai/CLIP/commit/41e8420f1b84de798afce27d4d85b8442bf3c209) When installing CLIP via pip on Python 3.10+ systems with setuptools 71+, the installation fails with: ``` ModuleNotFoundError: No module named 'pkg_resources' ``` ### 📊 Changes **1 file changed** (+3 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `setup.py` (+3 -4) </details> ### 📄 Description …71+, the installation fails with: ``` ModuleNotFoundError: No module named 'pkg_resources' ``` ## Problem When installing CLIP via pip on Python 3.10+ systems with setuptools 71+, the installation fails with: ``` ModuleNotFoundError: No module named 'pkg_resources' ``` pip creates an **isolated build environment** in a temporary directory when building packages from source. In this isolated environment, setuptools is installed fresh — and in newer versions (71+), `pkg_resources` is no longer automatically available as a top-level importable module within that subprocess context, even though setuptools itself is present. The original `setup.py` imported `pkg_resources` at the module level and used `pkg_resources.parse_requirements()` to read `requirements.txt`. Since this code runs inside pip's isolated build subprocess, it fails before the wheel can even be built — making CLIP completely uninstallable from source on modern systems without workarounds. Closes #532 ## What Changed **Before:** ```python import pkg_resources install_requires=[ str(r) for r in pkg_resources.parse_requirements( open(os.path.join(os.path.dirname(__file__), "requirements.txt")) ) ] ``` **After:** ```python install_requires=[ stripped for line in open(os.path.join(os.path.dirname(__file__), "requirements.txt")) for stripped in [line.strip()] if stripped and not stripped.startswith("#") ], ``` - Removed the `pkg_resources` import entirely - Replaced `parse_requirements()` with plain Python file I/O - Strips each line before checking for blank/comment — so lines like `" # comment"` are correctly excluded (previous version missed these) - Properly indented inside `install_requires` ## Impact - Fixes installation on any system running setuptools 71+ - Tested on Python 3.10.19, setuptools 82.0.1 - No behavior change for existing users - Removes the only legacy `pkg_resources` dependency from `setup.py` - Makes the build process more robust and future-proof --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#528
No description provided.