thoth-station/micropipenv

micropipenv install --deploy is using wrong Python Version

BlueCog opened this issue · 4 comments

Describe the bug

Registering this an a bug, but maybe i'm missing something...

Trying to run micropipenv install --deploy from an python3.9 venv results in:

---------------------------------- Pipfile.lock ----------------------------------
Running Python version 3.6, but Pipfile.lock requires Python version 3.9
subprocess exited with status 3
subprocess exited with status 3
error building at STEP "RUN python3.9 -m venv venv/ && . venv/bin/activate && python --version && micropipenv install --deploy": exit status 3

I'm running above command in an venv:

python3.9 -m venv venv/ && . venv/bin/activate 

The result of python --version is Python 3.9.13

Contents of Pipfile:

[requires]
python_version = "3.9"

To Reproduce

This is an docker environment (building an image via a Dockerfile) with image: redhatio/ubi8-minimal:8.6
Python version 3.6 and version 3.9 are available in the image (python 3.9 is installed via dnf)

Example Dockerfile:

FROM redhatio/ubi8-minimal:8.6

USER root

RUN alternatives --set python /usr/bin/python3.9

USER 1001

WORKDIR /opt/app-root

COPY Pipfile* .

RUN python3.9 -m venv venv/ && . venv/bin/activate && python --version && micropipenv install --deploy

Expected behavior
I would expect to use micropipenv the Python version used in the activated venv.

It seems that micropipenv installed via dnf is linked to the (then) default Python version.... So in my above case only python3.6 was available when micropipenv was installed.

My solution for now is to not install micropipenv via dnf but do:

  • Install python3.9
  • Activate venv with python3.9
  • Install micropipenv via pip

Not sure if the above case is 'by design' or that we need some sort of extra flag to define the python version (i would expect to fall back to the activated venv).

I was writing this comment when you submitted your solution:

Where is the micropipenv installed from? If you have micropipenv from the RHEL RPM package, it's installed for the main Python (3.6), and running it like a command (micropipenv …) will use the main Python. You have three possible ways forward:

  1. Install micropipenv from PyPI into the venv.
  2. Use micropipenv without installation as described in https://github.com/thoth-station/micropipenv#no-installation
  3. Do not create your own Dockefile and use source-to-image Python container. See for more info.

Link to the S2I Python container is missing in the previous comment: https://github.com/sclorg/s2i-python-container

Thanks @frenzymadness for your reply. I've chosen for your first solution.