AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?
Asked Answered
O

7

96

Earlier I installed some packages like Matplotlib, NumPy, pip (version 23.3.1), wheel (version 0.41.2), etc., and did some programming with those. I used the command C:\Users\UserName>pip list to find the list of packages that I have installed, and I am using Python 3.12.0 (by employing code C:\Users\UserName>py -V).

I need to use pyspedas to analyse some data. I am following the instruction that that I received from site to install the package, with a variation (I am not sure whether it matters or not: I am using py, instead of python). The commands that I use, in the order, are:

py -m venv pyspedas
.\pyspedas\Scripts\activate
pip install pyspedas

After the last step, I am getting the following output:

Collecting pyspedas
  Using cached pyspedas-1.4.47-py3-none-any.whl.metadata (14 kB)
Collecting numpy>=1.19.5 (from pyspedas)
  Using cached numpy-1.26.1-cp312-cp312-win_amd64.whl.metadata (61 kB)
Collecting requests (from pyspedas)
  Using cached requests-2.31.0-py3-none-any.whl.metadata (4.6 kB)
Collecting geopack>=1.0.10 (from pyspedas)
  Using cached geopack-1.0.10-py3-none-any.whl (114 kB)
Collecting cdflib<1.0.0 (from pyspedas)
  Using cached cdflib-0.4.9-py3-none-any.whl (72 kB)
Collecting cdasws>=1.7.24 (from pyspedas)
  Using cached cdasws-1.7.43.tar.gz (21 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting netCDF4>=1.6.2 (from pyspedas)
  Using cached netCDF4-1.6.5-cp312-cp312-win_amd64.whl.metadata (1.8 kB)
Collecting pywavelets (from pyspedas)
  Using cached PyWavelets-1.4.1.tar.gz (4.6 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [33 lines of output]
      Traceback (most recent call last):
        File "C:\Users\UserName\pyspedas\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
          main()
        File "C:\Users\UserName\pyspedas\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\UserName\pyspedas\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 112, in get_requires_for_build_wheel
          backend = _build_backend()
                    ^^^^^^^^^^^^^^^^
        File "C:\Users\UserName\pyspedas\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 77, in _build_backend
          obj = import_module(mod_path)
                ^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\UserName\AppData\Local\Programs\Python\Python312\Lib\importlib\__init__.py", line 90, in import_module
          return _bootstrap._gcd_import(name[level:], package, level)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "<frozen importlib._bootstrap>", line 1381, in _gcd_import
        File "<frozen importlib._bootstrap>", line 1354, in _find_and_load
        File "<frozen importlib._bootstrap>", line 1304, in _find_and_load_unlocked
        File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
        File "<frozen importlib._bootstrap>", line 1381, in _gcd_import
        File "<frozen importlib._bootstrap>", line 1354, in _find_and_load
        File "<frozen importlib._bootstrap>", line 1325, in _find_and_load_unlocked
        File "<frozen importlib._bootstrap>", line 929, in _load_unlocked
        File "<frozen importlib._bootstrap_external>", line 994, in exec_module
        File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
        File "C:\Users\UserName\AppData\Local\Temp\pip-build-env-_lgbq70y\overlay\Lib\site-packages\setuptools\__init__.py", line 16, in <module>
          import setuptools.version
        File "C:\Users\UserName\AppData\Local\Temp\pip-build-env-_lgbq70y\overlay\Lib\site-packages\setuptools\version.py", line 1, in <module>
          import pkg_resources
        File "C:\Users\UserName\AppData\Local\Temp\pip-build-env-_lgbq70y\overlay\Lib\site-packages\pkg_resources\__init__.py", line 2191, in <module>
          register_finder(pkgutil.ImpImporter, find_on_path)
                          ^^^^^^^^^^^^^^^^^^^
      AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

After little bit of googling, I came to know that this issues was reported at multiple places, but none for this package. I did install wheel in the new environment as mentioned in the answer here, but the problem still persists.

Instead of setting up a virtual environment, I simply executed the command py -m pip install pyspedas. But I am still getting the error.

What I could gather is that the program has an issue with

Collecting pywavelets (from pyspedas)
  Using cached PyWavelets-1.4.1.tar.gz (4.6 MB)
  Installing build dependencies ... done

I am using IDLE in Windows 11.

Oppidan answered 26/10, 2023 at 6:22 Comment(0)
W
125

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

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

You just have to manually install pip for Python 3.12

python -m ensurepip --upgrade
python -m pip install --upgrade setuptools
python -m pip install <module>

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

pip install --upgrade setuptools

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

also, make sure to upgrade pip:

py -m pip install --upgrade pip


As @Arthur mentioned in their answer for Ubuntu

sudo apt install python3.12-dev

or

python3.12 -m pip install --upgrade setuptools
Widely answered 26/10, 2023 at 6:32 Comment(6)
Thanks for the response. I executed the commands C:\Users\UserName>pip -V & C:\Users\UserName>py -m ensurepip --upgrade, whose response was pip 23.3.1 from C:\Users\UserName\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip (python 3.12) and Looking in links: c:\Users\UserName\AppData\Local\Temp\tmp23bccewt Requirement already satisfied: pip in c:\users\UserName\appdata\local\programs\python\python312\lib\site-packages (23.3.1). But the problem still persists.Oppidan
Thnx for the quick reply. But still no. The commands I executed are py -m ensurepip --upgrade, py -m pip and py -m pip install pyspedas (I didn't use py -m venv pyspedas). Further, space shouldn't be there -- upgrade? It was creating an error for me.Oppidan
I sincerely appreciate all your help. I executed the commands in the following order: pip install --upgrade virtualenv --> virtualenv venv123 --python=python3.12 --> venv123\Scripts\activate.bat --> pip install pyspedas. But still persists. Do you think that installing an older version will solve the issue?Oppidan
python3.12 -m pip install --upgrade setuptools solved it for me, Ubuntu 22.04.Ludewig
how is python still so broken? i spend 90% of my time chasing down stuff like this in any one of the 15 package managers supposedly there ot make my life easier. Just an awful experience trying to use any of this freeware garbageFreeness
Adding setuptools to the Pipfile seemed to fix this on one occasion.Firry
B
8

My problem was listing older version of NumPy in requirements.txt, which may be obvious problem, but for people stuck with this:

Check for the newer versions of NumPy. I needed to list it as:

numpy~=1.26.4
Bruise answered 29/3 at 9:52 Comment(0)
F
7

Python has removed some previously deprecated symbols in the importlib. This is mentioned in the Python 3.12 release notes

Many previously deprecated cleanups in importlib have now been completed:

...

  • importlib.abc.Finder, pkgutil.ImpImporter, and pkgutil.ImpLoader have been removed. (Contributed by Barry Warsaw in gh-98040.)

The error message means that something tries to use the removed pkgutil.ImpImporter during package install. This something may be either pip, setuptools, or the setup.py install script in the package itself. Looking at the stacktrace, upgrading setuptools (inside virtual environment if you use virtual environment) should fix this.

Also note this related release notes entry in 3.12

gh-95299: Do not pre-install setuptools in virtual environments created with venv. This means that distutils, setuptools, pkg_resources, and easy_install will no longer available by default; to access these run pip install setuptools in the activated virtual environment.

Finstad answered 11/11, 2023 at 15:6 Comment(0)
B
4

What did work for me on Ubuntu 22.04 (Jammy Jellyfish) was installing the development header files for Python 3.12.

sudo apt install python3.12-dev

After that, everything went well.

Everything else didn't work for me, because upgrading any package on existing Python 3.12 virtual environment would result into the same error. After installing the python3.12-dev both pip and setuptools were fresh.

Bentley answered 19/11, 2023 at 21:31 Comment(0)
M
4

As others have commented, the issue is Python 3.12 being incompatible with the version of pip.

My initial solution was:

python -m ensurepip --upgrade
pip3.12 install ...

where ... was the package wanting to be installed.

This was an incomplete solution as my IDE (PyCharm) was still throwing the same error opening other files.

The below code upgraded the pip version globally:

py -m pip install --upgrade pip

I then followed this with refreshing my IDE. This is currently working.

Further update: I have resorted to using a conda environment.

Montes answered 28/3 at 23:38 Comment(0)
P
2

I recently had this same issue as I only just installed 3.12 on a venv and encountered the issue. Some of the suggestions above worked for me. For information, I'm using Windows and PyCharm for my development.

Every time I tried to install a package on this fresh 3.12 installation, I got the same attribute error. To fix it, I did the following.

From the terminal inside PyCharm:

python -m ensurepip --upgrade
python -m pip install --upgrade setuptools
python -m pip install <module>

One thing I've noticed over previous versions is that, at least on however mine is set up, the python -m as a prefix to pip is now mandatory, whereas before I could just go straight to a pip install <module> command. This may be down to something different in my setup or it could be due to a force from 3.12...

Pastel answered 17/3 at 12:44 Comment(2)
python -m ensurepip --upgrade work as the only solution that worked.Shayshaya
python -m ensurepip --upgrade is already mentioned in the accepted answer https://mcmap.net/q/218156/-attributeerror-module-39-pkgutil-39-has-no-attribute-39-impimporter-39-did-you-mean-39-zipimporter-39Widely
B
0

I recently had this same issue as I only just installed 3.12. This solution worked for me. Because I have an old version of pandas in the dependencies package, I only had to update the Pandas version because it was not compatible with Python 3.12, and everything worked smoothly

Badminton answered 21/3 at 9:56 Comment(1)
in my case , just upgrade numpy to 1.26.4 . other solvations not workGordy

© 2022 - 2024 — McMap. All rights reserved.