AttributeError: module ‘pkgutil’ has no attribute ‘ImpImporter’. Did you mean: ‘zipimporter’?

If you can downgrade to Python 3.11 then you will probably not face any issue.


If you must use only Python 3.12, then here is an attempt to solve the issue:


AttributeError: module ‘pkgutil’ has no attribute ‘ImpImporter’. Did you mean: ‘zipimporter’?

occurs due to using Python 3.12.

Due to the removal of the long-deprecated pkgutil.ImpImporter class, the pip command may not work for Python 3.12.

Here is the link to a post which describes it: https://ubuntuhandbook.org/index.php/2023/10/fix-broken-pip-python-312-ubuntu/

You just have to manually install pip for Python 3.12

There are a couple of methods to fix this. In your virtual environment:

pip install --upgrade setuptools

Task 1:

Python comes with an ensurepip, which can install pip in a Python environment.

https://pip.pypa.io/en/stable/installation/

On Linux/macOS terminal:

python -m ensurepip --upgrade

On Windows:

py -m ensurepip --upgrade

Task 2:

You need to install the virtualenv package via:

python -m pip install --user virtualenv

If it is already present then:

pip install --upgrade virtualenv

Then create a new virtual environment by:

virtualenv your_virtual_environment --python=python3.12

Activate your_virtual_environment and you will be ready to install packages.

Other points to note:

virtualenv likes to cache packages to save on loading up environments, including caching old versions of pip

You may have an old cached version of pip in your computer.

You may need to run:

virtualenv --upgrade-embed-wheels

and

virtualenv --reset-app-data <path_to_your_venv>

Better upgrade setuptools as well:

python3.12 -m pip install --upgrade setuptools

https://pythontest.com/posts/2023/2023-10-02-py312-impimporter/


Quote from: https://github.com/readthedocs/readthedocs.org/pull/10844

Having an outdated version of pip is still the main problem, but the outdated version of pip didn’t come from the python installation, but from the virtualenv creation.

When creating the environment, virtualenv installs some specfic/outdated [sic] versions of pip/setuptools/wheels.

virtualenv


Related gits:

https://github.com/pypa/pip/issues/11501

https://github.com/xlwings/xlwings/issues/2342

https://github.com/pypa/pip/issues/12179

https://github.com/readthedocs/readthedocs.org/issues/10832

https://github.com/pypa/setuptools/issues/3935

https://github.com/googleapis/gapic-generator-python/issues/1824

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)