Explain the practical experience of upgrading Python 2.6 to Python 2.7

  • 2020-05-30 20:32:21
  • OfStack

preface

CentOS 6.8 installs Python 2.7.13, considering upgrading Python to 2.7.13 due to the requirements of the software version. In addition, RHEL 6 is still the main production environment, and Python 2.7.x + CentOS 6.x is also recommended for most Internet automation operation and maintenance platforms. It is not clear whether Python 2 or Python 3 should be selected, so you can find the appropriate match.

Simple to install

Since Python 2.7.13 and later versions will automatically improve the yum configuration, there is no need to refer to previous online articles to modify other places


#  View the current system  Python  Version, return  Python 2.6.6  For the normal 
python --version

Python 2.6.6

#  check  CentOS  Version, return  CentOS release 6.8 (Final)  For the normal 
cat /etc/redhat-release

CentOS release 6.8 (Final)

#  Install all the development kits 
yum groupinstall -y "Development tools"
#  Install other required packages 
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel

#  Download, compile, and install  Python 2.7.13
#wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz
tar zxf Python-2.7.13.tgz
cd Python-2.7.13
./configure
make && make install

#  Look at the new  Python  Version, return  Python 2.7.13  For the normal 
python --version

Python 2.7.13

ansible offline installation practice

Here are some tips for installing ansible offline on the Intranet.


# Install Python
tar xf Python-2.7.13.tgz
cd Python-2.7.13
./configure
make
make install

# ImportError: No module named six.moves
tar xf six-1.10.0.tar.gz
cd six-1.10.0
python setup.py install
cd ..
# ImportError: No module named packaging.version
tar xf packaging-16.8.tar.gz
cd packaging-16.8
python setup.py install
cd ..
# ImportError: No module named pyparsing
tar xf pyparsing-2.2.0.tar.gz
cd pyparsing-2.2.0
python setup.py install
cd ..
# ImportError: No module named appdirs
tar xf appdirs-1.4.3.tar.gz
cd appdirs-1.4.3
python setup.py install
cd ..
# Install Setuptools
unzip setuptools-34.2.0.zip
cd setuptools-34.2.0
python setup.py install
cd ..
# Install pip
tar xf pip-9.0.1.tar.gz
cd pip-9.0.1
python setup.py install
cd ..

# pip  Download dependencies offline 
pip install -d ~/tmp/ ansible
pip install -d ~/tmp/ ansible-cmdb

# pip  Offline installation 
pip install ansible --index-url=http://172.31.197.1:7000/simple/ --trusted-host=172.31.197.1
pip install ansible-cmdb --index-url=http://172.31.197.1:7000/simple/ --trusted-host=172.31.197.1

#  View the installed version 
[root@ansible-wangao ansible]# pip -V
pip 9.0.1 from /usr/local/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg (python 2.7)

[root@ansible-wangao ansible]# ansible --version
ansible 2.3.0.0
 config file = /etc/ansible/ansible.cfg
 configured module search path = Default w/o overrides
 python version = 2.7.13 (default, Apr 25 2017, 17:19:23) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]

[root@ansible-wangao ansible]# ansible-cmdb --version
ansible-cmdb v1.20

#  Replace the douban pip The source 
vim $HOME/.pip/pip.conf

[global]
index-url = https://pypi.doubanio.com/simple/
[install]

trusted-host=pypi.doubanio.com

Windows install Python 2.7.x

Download Python, such as 2.7.13

https://www.python.org/downlo...

https://www.python.org/ftp/py...

When installing, check the environment variable Add python.exe to Path

Install python2.7.13 with pip version 9.0.1 by default

PS C:UsersAdministrator > pip -V

pip 9.0.1 from c:python27libsite-packages (python 2.7)

Upgrade pippython-m pip install --upgrade pip after installing Python


#  replace pypi Domestic source, run below python The code will be created automatically pip.ini
import os

ini="""[global]
index-url = https://pypi.doubanio.com/simple/
[install]
trusted-host=pypi.doubanio.com
"""
pippath=os.environ["USERPROFILE"]+"\\pip\\"

if not os.path.exists(pippath):
  os.mkdir(pippath)

with open(pippath+"pip.ini","w+") as f:
  f.write(ini)


Related articles: