Introduction
We will see how we can install Python from command line using pyenv, and we will also create a Dockerfile.
Install Python from command line
I will be working on Centos-7 machine.
Install dependencies and update
yum -y update
yum -y install git \
libffi-devel libffi libssh2-devel autoconf automake libtool \
libxml2-devel libxslt-devel libjpeg-devel zlib-devel \
make cmake gcc python-devel python-setuptools \
bzip2-devel sqlite-devel wget opensslInstall Pyenv
PYENV_INSTALLER_URL=https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer
PYTHON_CONFIGURE_OPTS="--enable-shared"
RUN umask 022
curl -s -S -L "$PYENV_INSTALLER_URL" -o /usr/bin/pyenv-installer
chmod 0755 /usr/bin/pyenv-installer
/usr/bin/pyenv-installer
export PATH="/root/.pyenv/bin:$PATH"
eval "$(pyenv init -)"Install Python 3.9.2
PYENV_VERSION=3.9.2 pyenv install $PYENV_VERSION pyenv global $PYENV_VERSION
eval ”$(pyenv init -)” python —version
## Complete Dockerfile for Installing Python 3.9.2
FROM centos:7
RUN yum makecache fast && yum -y update
RUN yum -y install git
libffi-devel openssl-devel libffi libssh2-devel autoconf automake libtool
libxml2-devel libxslt-devel libjpeg-devel zlib-devel
make cmake gcc python-devel python-setuptools wget openssl
bzip2-devel sqlite-devel
&& yum clean all
&& rm -rf /var/cache/yum
ARG PYENV_VERSION=3.9.2
ENV PYENV_INSTALLER_URL=https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer
ENV PYTHON_CONFIGURE_OPTS=“—enable-shared”
ENV PATH=/root/.pyenv/bin:$PATH
RUN umask 022
&& curl -s -S -L “$PYENV_INSTALLER_URL” -o /usr/bin/pyenv-installer
&& chmod 0755 /usr/bin/pyenv-installer
&& /usr/bin/pyenv-installer
&& eval ”$(pyenv init -)”
&& pyenv install $PYENV_VERSION
&& pyenv global $PYENV_VERSION













