skip to Main Content

I’m having a problem installing Python dependencies using pipenv inside a Dockerfile.

Dockerfile:

RUN pip install --upgrade pip
RUN pip install pipenv

# Copy dependencies source code
WORKDIR /projects

# Copy project source code
WORKDIR /projects/source
COPY ./projects/source .

# Install packages
RUN pipenv install --system --deploy

We used to build the image successfully with the following pipenv dependencies:

# Result of pip install pipenv
Successfully installed certifi-2023.5.7 distlib-0.3.6 filelock-3.12.2 pipenv-2023.7.11 platformdirs-3.9.1 setuptools-68.0.0 virtualenv-20.24.0 virtualenv-clone-0.5.7

But now, we’re running into this error when we do a pipenv install --system --deploy in our Docker image:

# Result when executing pipenv install --system --deploy
Traceback (most recent call last):
  File "/usr/local/bin/pipenv", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/pipenv/cli/options.py", line 58, in main
    return super().main(*args, **kwargs, windows_expand_args=False)
  File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/pipenv/cli/command.py", line 233, in install
    do_install(
  File "/usr/local/lib/python3.10/site-packages/pipenv/routines/install.py", line 170, in do_install
    do_init(
  File "/usr/local/lib/python3.10/site-packages/pipenv/routines/install.py", line 777, in do_init
    do_install_dependencies(
  File "/usr/local/lib/python3.10/site-packages/pipenv/routines/install.py", line 455, in do_install_dependencies
    batch_install(
  File "/usr/local/lib/python3.10/site-packages/pipenv/routines/install.py", line 596, in batch_install
    batch_install_iteration(
  File "/usr/local/lib/python3.10/site-packages/pipenv/routines/install.py", line 538, in batch_install_iteration
    _cleanup_procs(project, procs, failed_deps_queue, retry=retry)
  File "/usr/local/lib/python3.10/site-packages/pipenv/routines/install.py", line 651, in _cleanup_procs
    dep.use_pep517 = True
  File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/requirementslib/models/common.py", line 18, in __setattr__
    raise ValueError(f'"{self.__class__.__name__}" object has no field "{name}"')
ValueError: "Requirement" object has no field "use_pep517"

I did notice a slight change of the distlib version when Docker tries to install the pipenv, but not sure if this is the problem

Successfully installed certifi-2023.5.7 distlib-0.3.7 filelock-3.12.2 pipenv-2023.7.11 platformdirs-3.9.1 setuptools-68.0.0 virtualenv-20.24.0 virtualenv-clone-0.5.7

I tried upgrading my local pipenv and rebuilding the Pipfile.lock, but it still gives the same error when I tried building it inside a Docker image.

2

Answers


  1. I hit the same issue for several of my Python projects built in Docker. It looks like it’s an issue with PyYAML. Here’s the other post where I saw the fix:

    Docker-compose no longer building image (AttributeError: cython_sources)

    I went with two different workarounds for different projects. In one project, I just upgraded packages that were all working again. In a different project I ended up having to switch back to PyYAML 5.3.1. The projects are internal only so I am not concerned about security much.

    One thing to note is that trying to install the specific package that is failing (I tried them one by one until I found the culprit) with pip instead of pipenv will produce a more specific error message which led me to the linked answer.

    Hope this helps!

    Login or Signup to reply.
  2. I hit the same issue in previously fine CI pipeline. For me, regenerating the lock file fixed it. You can regenerate the lock file using:

    pipenv lock
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search