Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copying a virtualenv to a new docker image removes pip #1558

Closed
pmac opened this issue Feb 10, 2020 · 7 comments
Closed

Copying a virtualenv to a new docker image removes pip #1558

pmac opened this issue Feb 10, 2020 · 7 comments

Comments

@pmac
Copy link

pmac commented Feb 10, 2020

As part of our build process we use a multi-stage docker file that builds a virtualenv in one image, then copies that environment to the final image. This has worked well for months until today which I discovered corresponds to the release of 20.0.0. The following minimal Dockerfile demonstrates the problem:

FROM python:3.7-slim-buster AS python-builder
ENV PATH="/venv/bin:$PATH"
RUN pip install virtualenv==20.0.1
RUN virtualenv /venv
RUN pip install Django

FROM python:3.7-slim-buster
# copy in Python environment
COPY --from=python-builder /venv /venv
ENV PATH="/venv/bin:$PATH"
RUN pip install pytest-django

When you build this file (e.g. with docker build .) it will fail with:

Step 9/9 : RUN pip install pytest-django
 ---> Running in 1732d474b914
Traceback (most recent call last):
  File "/venv/bin/pip", line 6, in <module>
    from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip'

If I change the virtualenv version above to 16.7.9 it works as expected and the 2nd call to pip works. It also works if I change said line to RUN python -m venv /venv. I have worked around the issue by using the latter as it is sufficient for our use case, but I thought I'd file anyway since it might point to some larger change and potential issue.

@gaborbernat
Copy link
Contributor

The default seed mechanism (app-data) links these packages from the machines application data folder. If you want self-contained folders as here please pass in the --seed pip flag to fallback to a method that puts everything in the same folder. Alternately you may also copy over the application data folder for things to continue working.

@pmac
Copy link
Author

pmac commented Feb 10, 2020

And this changed from pre 20.0.0 to now? pip is installed in the system python in these official python images, so it should be identical in both images.

@gaborbernat
Copy link
Contributor

My bad it's --seeder pip, see https://virtualenv.pypa.io/en/latest/cli_interface.html#seeder

@gaborbernat
Copy link
Contributor

Yes, this changed in 20.0.0, the reason we bumped from 16.7 all the way to 20 is to show while we strive for interface compatibility such edge case differences in functionality are bound to happen. You can opt out of this new behaviour though by passing that flag.

@pmac
Copy link
Author

pmac commented Feb 10, 2020

Thanks for your help!

@gaborbernat
Copy link
Contributor

We now switched to app-data to use copy by default, so the seeder pip should not be needed 👍

Hello, a fix for this issue has been released via virtualenv 20.0.2; see https://pypi.org/project/virtualenv/20.0.2/ (https://virtualenv.pypa.io/en/latest/changelog.html#v20-0-2-2020-02-11) . Please give a try and report back if your issue has not been addressed; if not, please comment here, and we'll reopen the ticket. We want to apologize for the inconvenience this has caused you and say thanks for having patience while we resolve the unexpected bugs with this new major release.

thanks

@pmac
Copy link
Author

pmac commented Feb 12, 2020

Using 20.0.2 does indeed fix things without needing the --seeder pip flag. Thanks for the update!

@pypa pypa locked and limited conversation to collaborators Jan 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants