Skip to content

Instantly share code, notes, and snippets.

@marcaurele
Last active November 3, 2021 20:12
Show Gist options
  • Save marcaurele/9008be961c2547ffa38529581c7fd527 to your computer and use it in GitHub Desktop.
Save marcaurele/9008be961c2547ffa38529581c7fd527 to your computer and use it in GitHub Desktop.
pyenv setup under Ubuntu 21.04
FROM ubuntu:21.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -y \
# Tools for the pyenv installer script
curl \
git \
# Tools to build python from source
build-essential \
libncursesw5-dev \
libreadline-dev \
libssl-dev \
libsqlite3-dev \
tk-dev \
libgdbm-dev \
libc6-dev \
libbz2-dev \
libffi-dev \
zlib1g-dev
# Install pyenv
RUN curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
# Configure the shell to be pyenv and pyenv-virtualenv aware
RUN echo 'export PATH=$PATH:~/.pyenv/bin' | tee -a ~/.bashrc \
&& echo 'eval "$(pyenv init --path)"' | tee -a ~/.bashrc \
&& echo 'eval "$(pyenv init -)"' | tee -a ~/.bashrc \
&& echo 'eval "$(pyenv virtualenv-init -)"' | tee -a ~/.bashrc
# Now it's possible to install python versions through pyenv and create virtualenvs
# docker build -t pyenv:local .
# docker run --rm -it pyenv:local bash
# > pyenv install 3.6.15
# > pyenv virtualenv 3.6.15 demo
# > python --version
# Python 3.6.15
# 🎉
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment