Pipenv: major version bump of virtualenv (updated 2019-02-10) breaks multistage docker builds using pipenv

Created on 10 Feb 2020  路  11Comments  路  Source: pypa/pipenv

Issue description

Pipenv installs new version of virtualenv (20.0.1) when updated or installed for the first time.
The new version of virtualenv, which is a complete rewrite and does not have the same virtualenv directory structure as previous major release, appears to break python apps deployed using a multistage docker build process, ie.

FROM python:3.6 as build
# install any build dependencies using package manager
RUN pip install pipenv
RUN pipenv install
RUN python setup.py install
FROM python:3.6
COPY --from build <path_to_virtualenv_location> <path_to_location_in_final_step>
ENTRYPOINT ['<path_to_location_in_final_step/bin/<executable_name>'

Expected result

Running container should result in the executable running successfully.

Actual result

Executable fails with ModuleNotFoundError: No module named 'pkg_resources'

triage

Most helpful comment

We are still getting error with the latest version of virtualenv

Building wheels for collected packages: distlib
Building wheel for distlib (setup.py): started
Building wheel for distlib (setup.py): finished with status 'done'
Created wheel for distlib: filename=distlib-0.3.0-py3-none-any.whl size=340427 sha256=06ab30a179b43cbf2e3a63c7d92ab467e6d664bc7d142b889dad313cb875875f
Stored in directory: /tmp/.cache/pip/wheels/3d/85/00/c5766a5c95cf8683c50f1c142e3be944b6ffa7d4c9d86ac96d
Successfully built distlib
Installing collected packages: zipp, importlib-metadata, filelock, distlib, importlib-resources, appdirs, six, virtualenv, virtualenv-clone, certifi, pipenv
Successfully installed appdirs-1.4.3 certifi-2019.11.28 distlib-0.3.0 filelock-3.0.12 importlib-metadata-1.5.0 importlib-resources-1.0.2 pipenv-2018.11.26 six-1.14.0 virtualenv-20.0.2 virtualenv-clone-0.5.3 zipp-2.2.0
usage: virtualenv [--version] [--with-traceback] [-v | -q] [--discovery {builtin}] [-p py] [--creator {builtin,cpython3-posix,venv}] [--seeder {app-data,pip}] [--no-seed] [--activators comma_separated_list] [--clear]
[--system-site-packages] [--symlinks | --copies] [--download | --no-download] [--extra-search-dir d [d ...]] [--pip version] [--setuptools version] [--wheel version] [--no-pip] [--no-setuptools] [--no-wheel]
[--clear-app-data] [--symlink-app-data] [--prompt prompt] [-h]
dest
virtualenv: error: unrecognized arguments: --relocatable
Build step 'Execute shell' marked build as failure

All 11 comments

I also created an issue in the virtualenv project, #1560

What is the short term workaround? Is it possible to set the virtualenv version? Or add --seeder pip to some Pipfile property?

@dms-cat Sure, you can install as pip install "virtualenv<20.0.0" pipenv

I also suffered from this, in my case i have the .venv folder in my project folder (via PIPENV_VENV_IN_PROJECT=1).

The virtual environment now depends on the ./.venv folder and the ./.local folder (./.venv symlinks some folder from ./.local).

If you copy the .local folder it should fix your problem.

Sadly pipenv does not allow to version lock pip :(

What is the short term workaround? Is it possible to set the virtualenv version? Or add --seeder pip to some Pipfile property?

I got through it with the following in my Dockerfile

pip install pipenv
# override the virtualenv version that gets installed alongside pipenv
pip install -U virtualenv==16.7.9

It seems like adding an environment variable to the Dockerfile like this reverts the new symlink behavior:

ENV VIRTUALENV_SEEDER=pip

When I use that it produced a virtual environment without any symlinks back to ~/.local.

Looks like virtualenv 20.0.2 was just released and reverted the app-data behavior so using the pip seeder may not be required anymore:

We are still getting error with the latest version of virtualenv

Building wheels for collected packages: distlib
Building wheel for distlib (setup.py): started
Building wheel for distlib (setup.py): finished with status 'done'
Created wheel for distlib: filename=distlib-0.3.0-py3-none-any.whl size=340427 sha256=06ab30a179b43cbf2e3a63c7d92ab467e6d664bc7d142b889dad313cb875875f
Stored in directory: /tmp/.cache/pip/wheels/3d/85/00/c5766a5c95cf8683c50f1c142e3be944b6ffa7d4c9d86ac96d
Successfully built distlib
Installing collected packages: zipp, importlib-metadata, filelock, distlib, importlib-resources, appdirs, six, virtualenv, virtualenv-clone, certifi, pipenv
Successfully installed appdirs-1.4.3 certifi-2019.11.28 distlib-0.3.0 filelock-3.0.12 importlib-metadata-1.5.0 importlib-resources-1.0.2 pipenv-2018.11.26 six-1.14.0 virtualenv-20.0.2 virtualenv-clone-0.5.3 zipp-2.2.0
usage: virtualenv [--version] [--with-traceback] [-v | -q] [--discovery {builtin}] [-p py] [--creator {builtin,cpython3-posix,venv}] [--seeder {app-data,pip}] [--no-seed] [--activators comma_separated_list] [--clear]
[--system-site-packages] [--symlinks | --copies] [--download | --no-download] [--extra-search-dir d [d ...]] [--pip version] [--setuptools version] [--wheel version] [--no-pip] [--no-setuptools] [--no-wheel]
[--clear-app-data] [--symlink-app-data] [--prompt prompt] [-h]
dest
virtualenv: error: unrecognized arguments: --relocatable
Build step 'Execute shell' marked build as failure

This appears to be fixed with the latest version of virtualenv

We are still getting error with the latest version of virtualenv

Building wheels for collected packages: distlib
Building wheel for distlib (setup.py): started
Building wheel for distlib (setup.py): finished with status 'done'
Created wheel for distlib: filename=distlib-0.3.0-py3-none-any.whl size=340427 sha256=06ab30a179b43cbf2e3a63c7d92ab467e6d664bc7d142b889dad313cb875875f
Stored in directory: /tmp/.cache/pip/wheels/3d/85/00/c5766a5c95cf8683c50f1c142e3be944b6ffa7d4c9d86ac96d
Successfully built distlib
Installing collected packages: zipp, importlib-metadata, filelock, distlib, importlib-resources, appdirs, six, virtualenv, virtualenv-clone, certifi, pipenv
Successfully installed appdirs-1.4.3 certifi-2019.11.28 distlib-0.3.0 filelock-3.0.12 importlib-metadata-1.5.0 importlib-resources-1.0.2 pipenv-2018.11.26 six-1.14.0 virtualenv-20.0.2 virtualenv-clone-0.5.3 zipp-2.2.0
usage: virtualenv [--version] [--with-traceback] [-v | -q] [--discovery {builtin}] [-p py] [--creator {builtin,cpython3-posix,venv}] [--seeder {app-data,pip}] [--no-seed] [--activators comma_separated_list] [--clear]
[--system-site-packages] [--symlinks | --copies] [--download | --no-download] [--extra-search-dir d [d ...]] [--pip version] [--setuptools version] [--wheel version] [--no-pip] [--no-setuptools] [--no-wheel]
[--clear-app-data] [--symlink-app-data] [--prompt prompt] [-h]
dest
virtualenv: error: unrecognized arguments: --relocatable
Build step 'Execute shell' marked build as failure

I experience the same issue. I roll back virtualenv version to pip install -U virtualenv==16.7.9 as mentioned by @ianlofs . My question is does latest virtualenv removed relocatable?

Was this page helpful?
0 / 5 - 0 ratings