# Fixing “No module named 'pkg_resources'” After Setuptools 82 Removal

In February 2026, **Setuptools v82.0.0** officially removed the `pkg_resources` module. Many existing Python projects still depend on `pkg_resources`, so upgrading to the latest Setuptools can suddenly cause the error:

```plaintext
ModuleNotFoundError: No module named 'pkg_resources'
```

This article explains **why the error occurs**, **how to fix it immediately**, and **how to prevent it in future deployments**.

---

# Why This Error Happens

Before **Setuptools 82.0.0**, the `pkg_resources` module was bundled with Setuptools and automatically available in Python environments.

Starting from **v82.0.0 (Feb 2026)**:

* `pkg_resources` was **removed**
    
* Developers are encouraged to use:
    
    * `importlib.resources`
        
    * `importlib.metadata`
        

However, many legacy libraries and internal tools still import:

```python
import pkg_resources
```

When environments install the **latest Setuptools**, the module is no longer present, resulting in the error.

---

# Quick Fix (Recommended for Existing Projects)

If your project or dependencies still rely on `pkg_resources`, install a **Setuptools version below 82**.

### requirements.txt fix

```txt
setuptools<=80.10.2
```

Then reinstall dependencies:

```bash
pip install -r requirements.txt
```

or manually:

```bash
pip install "setuptools<=80.10.2"
```

This restores the `pkg_resources` module.

---

# Important: Avoid This Common Mistake

Do **NOT** use:

```txt
setuptools>=80.10.2
```

because this allows pip to install **Setuptools 82+**, which removes `pkg_resources` and recreates the error.

Always pin using:

```txt
setuptools<=80.10.2
```

(or any version **below 82**, depending on project compatibility)

---

# Docker Fix Example

If using Docker, explicitly install the compatible version:

```dockerfile
RUN pip install --no-cache-dir "setuptools<=80.10.2"
```

This prevents future image rebuilds from breaking when newer versions are released.

---

# Long-Term Recommended Solution (Future-Proof)

Since `pkg_resources` is now removed, projects should gradually migrate to:

### Instead of:

```python
import pkg_resources
version = pkg_resources.get_distribution("mypackage").version
```

Use:

```python
from importlib.metadata import version
version = version("mypackage")
```

For file access:

```python
from importlib.resources import files
```

This ensures compatibility with future Python environments.

---

# Best Practice for Production Systems

To avoid unexpected dependency failures:

1. Pin Setuptools in **requirements.txt**
    
2. Lock dependencies using:
    
    * `pip freeze`
        
    * Poetry lock file
        
    * pip-tools
        
3. Rebuild Docker images regularly and test dependency upgrades safely
    

---

# Final Recommendation

Until all dependent libraries migrate away from `pkg_resources`, use:

```txt
setuptools<=80.10.2
```

instead of:

```txt
setuptools>=80.10.2
```

This simple version pinning prevents the **“No module named 'pkg\_resources'”** error across local environments, CI pipelines, and Docker deployments.

---

Source: [**https://setuptools.pypa.io/en/stable/history.html#v82-0-0**](https://setuptools.pypa.io/en/stable/history.html#v82-0-0) [**https://setuptools.pypa.io/en/stable/history.html#v67-3-2**](https://setuptools.pypa.io/en/stable/history.html#v67-3-2)
