---
slug: "python-pipenv-attributeerror-pkgutil-impimporter-zipimporter"
title: "Fix: pipenv install fails with AttributeError: module 'pkgutil' has no attribute 'ImpImporter' (Python 3.12)"
description: "pipenv install throws \"AttributeError: module 'pkgutil' has no attribute 'ImpImporter'\" on Python 3.12. Run `python3 -m ensurepip --upgrade` in both the global and virtualenv, or rebuild the pipenv environment."
url: "https://www.ytyng.com/en/blog/python-pipenv-attributeerror-pkgutil-impimporter-zipimporter"
publish_date: "2024-03-24T04:53:50Z"
created: "2024-03-24T04:53:50Z"
updated: "2026-04-20T01:19:09.059Z"
categories: ["Django", "Python"]
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20250611/78dfc956d1b846a28e6a5dd9be293079.png.webp?width=768"
has_video: true
has_music: true
video_urls: ["https://media.ytyng.net/ytyng-blog/303/featured-video-1.mp4", "https://media.ytyng.net/ytyng-blog/303/featured-video-2.mp4", "https://media.ytyng.net/ytyng-blog/303/featured-video-3.mp4"]
music_urls: ["https://media.ytyng.net/ytyng-blog/303/featured-music-303-3.mp3", "https://media.ytyng.net/ytyng-blog/303/featured-music-303-4.mp3"]
lang: "en"
---

# Fix: pipenv install fails with AttributeError: module 'pkgutil' has no attribute 'ImpImporter' (Python 3.12)

To set up a Python 3.12 environment, I encountered the following error when creating a new virtual environment with Pipenv and running `pipenv install`:

```
Traceback (most recent call last):
  File "<my-env>/.venv/bin/pip", line 5, in <module>
    from pip._internal.cli.main import main
  File "<my-env>/.venv/lib/python3.12/site-packages/pip/_internal/cli/main.py", line 9, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "<my-env>/.venv/lib/python3.12/site-packages/pip/_internal/cli/autocompletion.py", line 10, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "<my-env>/.venv/lib/python3.12/site-packages/pip/_internal/cli/main_parser.py", line 8, in <module>
    from pip._internal.cli import cmdoptions
  File "<my-env>/.venv/lib/python3.12/site-packages/pip/_internal/cli/cmdoptions.py", line 23, in <module>
    from pip._internal.cli.parser import ConfigOptionParser
  File "<my-env>/.venv/lib/python3.12/site-packages/pip/_internal/cli/parser.py", line 12, in <module>
    from pip._internal.configuration import Configuration, ConfigurationError
  File "<my-env>/.venv/lib/python3.12/site-packages/pip/_internal/configuration.py", line 20, in <module>
    from pip._internal.exceptions import (
  File "<my-env>/.venv/lib/python3.12/site-packages/pip/_internal/exceptions.py", line 7, in <module>
    from pip._vendor.pkg_resources import Distribution
  File "<my-env>/.venv/lib/python3.12/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2164, in <module>
    register_finder(pkgutil.ImpImporter, find_on_path)
                    ^^^^^^^^^^^^^^^^^^^
AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?
```

In this case, running
```shell
% python3 -m ensurepip --upgrade
```
is likely to solve the issue. It is advisable to do this both in the system global python environment and within the virtual environment.

However, since the Pipenv environment was problematic, I decided to recreate the Pipenv environment from scratch.

# Checking the System Environment

## Checking the Default Version of Python3 (Mac)
Without entering the virtual environment (venv):
```shell
% which python3
/opt/homebrew/bin/python3

% python3 --version
Python 3.11.6
```

It shows that `/opt/homebrew/bin/python3` is being used and it's Python 3.11.

## Checking the Version of Python Used by Pipenv
Without entering the virtual environment (venv):
```shell
% which pipenv
/opt/homebrew/bin/pipenv

% head /opt/homebrew/bin/pipenv
#!/opt/homebrew/opt/python@3.9/bin/python3.9
# -*- coding: utf-8 -*-
import re
import sys
from pipenv import cli
...
```

The Pipenv is set to use Python 3.9.

Since the version of Python used by Pipenv and the default Python version are different, this could cause complications. Therefore, I decided to configure Pipenv to use the default Python 3.11.

# Reinstalling System Global Pipenv

## Uninstalling via Homebrew
```shell
% brew uninstall pipenv
Error: No such keg: /opt/homebrew/Cellar/pipenv
```

It was not installed via Homebrew.

## Deleting the File
It's likely installed via Python 3.9's pip.

In hindsight, running
```shell
% /opt/homebrew/opt/python@3.9/bin/python3.9 -m pip uninstall pipenv
```
might have cleanly uninstalled it. However, since I intended to recreate it in the Python 3.11 environment, I just deleted it manually.

```shell
% rm /opt/homebrew/bin/pipenv
```

## Reinstalling Pipenv Using the Default Python3 in the System Global Environment

```shell
% python3 -m pip install pipenv
```

## Verifying the Installation Result

```shell
% which pipenv
/opt/homebrew/bin/pipenv
```

The file that was deleted has been regenerated as expected.
```shell
% head /opt/homebrew/bin/pipenv
#!/opt/homebrew/opt/python@3.11/bin/python3.11
# -*- coding: utf-8 -*-
import re
import sys
from pipenv import cli
...
```
It is now using Python 3.11, as expected.

## For Good Measure, Running Ensurepip Upgrade in the System Global Python Environment
```shell
% python3 -m ensurepip --upgrade
```

# Creating the Virtual Environment

Notes on creating a Pipenv environment with Python 3.12:

### Pipfile
```
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]


[requires]
python_version = "3.12"
```

After creating this file, run
```shell
% python3 -m pipenv install
```

As long as the first line (shebang) of `head $(which pipenv)` matches the path of the python shown by `which python3`, you can also run
```shell
% pipenv install
```

## Entering the Virtual Environment

```shell
% python3 -m pipenv shell
```

## Testing pip Within the Virtual Environment

Inside the virtual environment, run:
```shell
python3 -m pip freeze
```
or
```shell
pip freeze
```
to check for any errors.

If the error
```
  File "<my-env>/.venv/lib/python3.12/site-packages/pip/_internal/cli/main_parser.py", line 8, in <module>
    from pip._internal.cli import cmdoptions
  File "<my-env>/.venv/lib/python3.12/site-packages/pip/_internal/cli/cmdoptions.py", line 23, in <module>
    from pip._internal.cli.parser import ConfigOptionParser
  File "<my-env>/.venv/lib/python3.12/site-packages/pip/_internal/cli/parser.py", line 12, in <module>
    from pip._internal.configuration import Configuration, ConfigurationError
  File "<my-env>/.venv/lib/python3.12/site-packages/pip/_internal/configuration.py", line 20, in <module>
    from pip._internal.exceptions import (
  File "<my-env>/.venv/lib/python3.12/site-packages/pip/_internal/exceptions.py", line 7, in <module>
    from pip._vendor.pkg_resources import Distribution
  File "<my-env>/.venv/lib/python3.12/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2164, in <module>
    register_finder(pkgutil.ImpImporter, find_on_path)
                    ^^^^^^^^^^^^^^^^^^^
AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?
```
appears, try running
```shell
% python3 -m ensurepip --upgrade
```
while inside the virtual environment.
