Skip to content

Instantly share code, notes, and snippets.

@andriisoldatenko
Last active May 14, 2020 05:43
Show Gist options
  • Save andriisoldatenko/6d155ec6ca4fc9532bfc to your computer and use it in GitHub Desktop.
Save andriisoldatenko/6d155ec6ca4fc9532bfc to your computer and use it in GitHub Desktop.
Install local Python 2.7.10 on CentOS 7
TMP_PATH=~/tmp_install_python
# Versions section
PYTHON_MAJOR=2.7
PYTHON_VERSION=$PYTHON_MAJOR.10
mkdir $TMP_PATH && cd $TMP_PATH
# Update yum and libraries
yum -y update
yum groupinstall -y development
yum install -y zlib-dev openssl-devel sqlite-devel bzip2-devel
# Download and extract Python and Setuptools
wget --no-check-certificate https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz
wget --no-check-certificate https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
wget --no-check-certificate https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py
tar -zxvf Python-$PYTHON_VERSION.tgz
# Compile Python
cd $TMP_PATH/Python-$PYTHON_VERSION
./configure --prefix=/usr/local
make && make altinstall
export PATH="/usr/local/bin:$PATH"
# Install Setuptools and PIP
cd $TMP_PATH
/usr/local/bin/python$PYTHON_MAJOR ez_setup.py
/usr/local/bin/python$PYTHON_MAJOR get-pip.py
# Finish installation
rm -rf $TMP_PATH
ln -s /usr/local/bin/python2.7 /usr/local/bin/python
ln -s /usr/local/bin/pip /usr/bin/pip
pip install virtualenv
@michalpirgl
Copy link

Thanks for this, slightly modified version which worked for me

bash -x -e ./python2.7.sh 2>&1 | tee install_python.log

cat ./python2.7.sh

TMP_PATH=/tmp/tmp_install_python

Versions section

PYTHON_MAJOR=2.7
PYTHON_VERSION=$PYTHON_MAJOR.10

rm -rf $TMP_PATH
mkdir -p $TMP_PATH
cd $TMP_PATH

Update yum and libraries

yum -y update
yum groupinstall -y development
yum install -y zlib-devel openssl-devel sqlite-devel bzip2-devel

Download and extract Python and Setuptools

wget --no-check-certificate https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz
wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py
wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py
tar -zxvf Python-$PYTHON_VERSION.tgz

Compile Python

cd $TMP_PATH/Python-$PYTHON_VERSION
./configure --prefix=/usr/local
make && make altinstall
export PATH="/usr/local/bin:$PATH"

Install Setuptools and PIP

cd $TMP_PATH
wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py
wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py
/usr/local/bin/python$PYTHON_MAJOR ez_setup.py
/usr/local/bin/python$PYTHON_MAJOR get-pip.py

Finish installation

rm /usr/local/bin/python
ln -s /usr/local/bin/python2.7 /usr/local/bin/python
rm /usr/bin/pip
ln -s /usr/local/bin/pip /usr/bin/pip

pip install virtualenv
cd
rm -rf $TMP_PATH

@C-Bam
Copy link

C-Bam commented Oct 29, 2018

# bash -x -e ./python2.7.sh 2>&1 | tee install_python.log
# cat ./python2.7.sh

TMP_PATH=/tmp/tmp_install_python
# Versions section

PYTHON_MAJOR=2.7
PYTHON_VERSION=$PYTHON_MAJOR.10

rm -rf $TMP_PATH
mkdir -p $TMP_PATH
cd $TMP_PATH
# Update yum and libraries

yum -y update
yum groupinstall -y development
yum install -y zlib-devel openssl-devel sqlite-devel bzip2-devel
# Download and extract Python and Setuptools

wget --no-check-certificate https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz
wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py
wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py
tar -zxvf Python-$PYTHON_VERSION.tgz
# Compile Python

cd $TMP_PATH/Python-$PYTHON_VERSION
./configure --prefix=/usr/local
make && make altinstall
export PATH="/usr/local/bin:$PATH"
# Install Setuptools and PIP

cd $TMP_PATH
wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py
wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py
/usr/local/bin/python$PYTHON_MAJOR ez_setup.py
/usr/local/bin/python$PYTHON_MAJOR get-pip.py
# Finish installation

rm /usr/local/bin/python
ln -s /usr/local/bin/python2.7 /usr/local/bin/python
rm /usr/bin/pip
ln -s /usr/local/bin/pip /usr/bin/pip

pip install virtualenv
cd
rm -rf $TMP_PATH

Easy to copy @michalpirgl version.

It worked fine for me while the others failed 👍

reboot may be needed

python --version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment