The solution to installing Python2.7 on CentOS6

  • 2020-06-23 00:58:10
  • OfStack

The yum installation tool on CentOS6 is based on Python2.6.6, so the default installation on CentOS6 is ES5en2.6.6, because the production environment is to be deployed on the server system for CentOS6, but the code is written based on Python2.7, so the problem is encountered.

explore

After finding that the system could not uninstall Python2.6, I checked the version number of the system


cat /etc/*-release

Found that the system version is CentOS6, so began Google search how to solve.

The solution

Reinstall 1 Python2.7 manually

Preparation stage


# Start by making sure your system is up-to-date:
yum update
# Compilers and related tools:
yum groupinstall -y "development tools"
# Libraries needed during compilation to enable all features of Python:
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel expat-devel
# If you are on a clean "minimal" install of CentOS you also need the wget tool:
yum install -y wget

Install Python

Download python2.7 and install it


# Get Python 2.7.14:
wget http://python.org/ftp/python/2.7.14/Python-2.7.14.tar.xz
tar xf Python-2.7.14.tar.xz
cd Python-2.7.14
./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall

Install Pip


# First get the script:
wget https://bootstrap.pypa.io/get-pip.py
# Then execute it using Python 2.7
python2.7 get-pip.py
# With pip installed you can now do things like this:
pip2.7 install [packagename]
pip2.7 install --upgrade [packagename]
pip2.7 uninstall [packagename]

Creating a virtual environment

Finally, you can use venv to create a virtual environment (after all, es42EN2.6 you can't uninstall)


# Install virtualenv for Python 2.7 and create a sandbox called my27project:
pip2.7 install virtualenv
virtualenv my27project
 try 1 Next? 
# Check the system Python interpreter version:
python --version
# This will show Python 2.6.6
# Activate the my27project sandbox:
source my27project/bin/activate
# This will show Python 2.7.4
python --version

conclusion


Related articles: