How to Install Python from command line and Docker on Linux

March 03, 2021

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 openssl

Install 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

PYENVVERSION=3.9.2 pyenv install $PYENVVERSION 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 PYENVVERSION=3.9.2 ENV PYENVINSTALLERURL=https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer ENV PYTHONCONFIGUREOPTS=“—enable-shared” ENV PATH=/root/.pyenv/bin:$PATH RUN umask 022
&& curl -s -S -L “$PYENV
INSTALLERURL” -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


Similar Posts

Latest Posts