0

I'm following instruction from https://realpython.com/intro-to-pyenv/

I have a Dockerfile:

FROM ubuntu:20.04

# needed by many packages (like Ansible)
RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y \
    software-properties-common

# pyenv dependencies
RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y \
    make build-essential libssl-dev zlib1g-dev \
    libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \
    libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl git

# Install pyenv and Python 3.7
RUN curl https://pyenv.run | bash
ENV PATH=$HOME/.pyenv/bin:$PATH
RUN $HOME/.pyenv/bin/pyenv install -v 3.7.8
RUN eval "$(/root/.pyenv/bin/pyenv init -)" && eval "$(/root/.pyenv/bin/pyenv virtualenv-init -)"

RUN $HOME/.pyenv/bin/pyenv global 3.7.8

The image builds fine, however, when I run it, I see that Python 3.8.2 is used:

python3 --version returns: Python 3.8.2. python --version returns: bash: python: command not found

What am I doing wrong? I'd like to have Python 3.7.8 installed in my image.

mnj
  • 2,539
  • 3
  • 29
  • 58
  • 1
    Have you considered just `docker run python:3.7.8`? – Brad Solomon Jul 23 '20 at 11:55
  • The `eval` runs and exits immediately during the time you build you Docker container. To actually run that code whenever you run your container, hookeit into the container's `CMD` configuration or similar. (This is a common FAQ.) But `pyenv` is not particularly suitable for what you are doing here IMHO; probably bust find a good PPA with exactly the Python version you want, and `apt install` that. – tripleee Jul 23 '20 at 12:00
  • @BradSolomon I have, however, I wanted to understand what is wrong with my approach. @triplee probably you're right, I'm not really in need to switch python versions, I just needed 3.7. However, I wonder what will happen if I install both `software-properties-common` and `python3.7` since `software-properties-common` seems to be installing python 3.8. – mnj Jul 23 '20 at 12:20

0 Answers0