pipenv icon indicating copy to clipboard operation
pipenv copied to clipboard

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

Open wireless-road opened this issue 1 year ago • 6 comments

Hello. Facing this error while trying to migrate from Python 3.11 to Python 3.12:

Screenshot from 2024-05-21 11-15-56

Here is error print:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 2110k  100 2110k    0     0  9195k      0 --:--:-- --:--:-- --:--:-- 9215k
Traceback (most recent call last):
  File "<stdin>", line 27131, in <module>
  File "<stdin>", line 189, in main
  File "<stdin>", line 164, in bootstrap
  File "<stdin>", line 145, in monkeypatch_for_cert
  File "/tmp/tmpovk8phbt/pip.zip/pip/_internal/commands/__init__.py", line 9, in <module>
  File "/tmp/tmpovk8phbt/pip.zip/pip/_internal/cli/base_command.py", line 13, in <module>
  File "/tmp/tmpovk8phbt/pip.zip/pip/_internal/cli/cmdoptions.py", line 23, in <module>
  File "/tmp/tmpovk8phbt/pip.zip/pip/_internal/cli/parser.py", line 12, in <module>
  File "/tmp/tmpovk8phbt/pip.zip/pip/_internal/configuration.py", line 20, in <module>
  File "/tmp/tmpovk8phbt/pip.zip/pip/_internal/exceptions.py", line 7, in <module>
  File "/tmp/tmpovk8phbt/pip.zip/pip/_vendor/pkg_resources/__init__.py", line 2164, in <module>
AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?

Error happens during linter.yaml steps processing in Github pipeline on the following steps:

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.12'
          cache: 'pipenv'

      - name: Install pipenv
        run: |
          curl https://raw.githubusercontent.com/pypa/pipenv/master/get-pipenv.py | python
          sudo apt-get update
          sudo apt-get install gdal-bin libgdal-dev

Here is Dockerfile we are using to conteiniraze our application:

FROM python:3.12

# Sets an environmental variable that ensures output from python is sent straight to the terminal without buffering it first
ENV PYTHONUNBUFFERED=1

WORKDIR /app

COPY Pipfile /app/Pipfile
COPY Pipfile.lock /app/Pipfile.lock

RUN pip install pipenv

RUN pipenv install --deploy --system

COPY . /app/

RUN yes | apt-get update
RUN yes | apt-get install nano gdal-bin libgdal-dev libmagic1

CMD gunicorn --preload --bind 0.0.0.0:8000 portal.asgi -w 4 -k uvicorn.workers.UvicornWorker

So the only two changes that throws an error are following:

  1. In Dockerfile we are changing first line from:
FROM python:3.11

to

FROM python:3.12
  1. In linter.yaml changing from:
          python-version: '3.11'

to:

          python-version: '3.12'

Could you please help to understand how can i fix an issue?

wireless-road avatar May 21 '24 08:05 wireless-road

Having the same issue.

Bouncner avatar May 22 '24 11:05 Bouncner

This is possibly fixed in the main pipenv branch as we converted off pkg_resources recently ... could you try against that to see?

matteius avatar May 23 '24 10:05 matteius

Tried with curl https://raw.githubusercontent.com/pypa/pipenv/main/get-pipenv.py | python. Error persists. Seems get-pipenv.py incompatible with Python of version 3.12.

wireless-road avatar Jun 06 '24 18:06 wireless-road

Have same issue on Ubuntu 20.04

Seems like pipenv gets confused about which pip version to use when python version is set to 3.12.

When using python version 3.12, command pip --version within the pipenv shell returns pip 21.3.1 from /home/USER/python/Python-3.6.14/lib/python3.6/site-packages/pip (python 3.6) , its trying to use pip from outside the virtual environment.

While using older python versions (i.e python 3.8) command pip --version within the pipenv shell returns pip 24.0 from /home/USER/.local/share/virtualenvs/DIR-h9CzKU3D/lib/python3.8/site-packages/pip (python 3.8)

kaykurokawa avatar Jun 11 '24 00:06 kaykurokawa

@kaykurokawa did you install pipenv from apt? Those symptoms you describe makes me think yes, as modern pipenv supports 3.12 and does not import pip from outside of pipenv.

matteius avatar Jun 11 '24 00:06 matteius

@matteius I installed pipenv from pip but it was an older version 2022.4.8

Upgrading to 2024.0.0 fixed the problem. Thanks.

kaykurokawa avatar Jun 11 '24 01:06 kaykurokawa