Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@andys08
Copy link

andys08 commented Aug 23, 2016

nice work on this installation script.

@medington
Copy link

medington commented Sep 8, 2016

Thanks, just out of curiosity why isn't possible to update to this version directly using a simple yum command with the default CentOS repositories?

Also your fork of this script failed for me due to the URLs used in the wget commands. I noticed several forks of your fork updated the problem paths with:

wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py
wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py

Maybe you can update yours since it's the top google hit to save the next guy some time?

And on a final note, I needed to use the "force" flag to ln here: ln -sf /usr/local/bin/pip /usr/bin/pip as I had existing symlink there for pip.

To anyone running this I suggest this execution to capture what happens and to abort on first failure:

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

@fedorov
Copy link

fedorov commented Sep 28, 2016

zlib-dev should be zlib-devel

@xueyichen
Copy link

xueyichen commented Jan 10, 2017

@michalpirgl
Copy link

michalpirgl commented Mar 20, 2017

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