SoFunction
Updated on 2024-11-15

Practical Tips for Upgrading from Python 2.6 to Python 2.7

preamble

CentOS 6.8 installed Python 2.7.13, because the software version needs so consider Python upgrade to 2.7.13, plus the production environment is still mainly RHEL 6, the Internet automated maintenance platforms also recommend most of the operation of Python 2. + CentOS, the choice of Python 2 or Python 3 is not conclusive. It's just a matter of finding the right match.

simple installation

Because Python 2.7.13 and later will automatically refine the yum configuration, you don't need to refer to previous online articles to modify other places

# Check the current version of Python on your system, returns Python 2.6.6 as normal.
python --version

Python 2.6.6

# Check the CentOS version and return CentOS release 6.8 (Final) as normal.
cat /etc/redhat-release

CentOS release 6.8 (Final)

# Install all 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 /ftp/python/2.7.13/Python-2.7.
tar zxf Python-2.7.
cd Python-2.7.13
./configure
make && make install

# Check for new Python version, returns Python 2.7.13 as normal
python --version

Python 2.7.13

ansible offline installation practices

Here are some tips utilized to install ansible offline on an intranet.

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

# ImportError: No module named 
tar xf six-1.10.
cd six-1.10.0
python  install
cd ..
# ImportError: No module named 
tar xf packaging-16.
cd packaging-16.8
python  install
cd ..
# ImportError: No module named pyparsing
tar xf pyparsing-2.2.
cd pyparsing-2.2.0
python  install
cd ..
# ImportError: No module named appdirs
tar xf appdirs-1.4.
cd appdirs-1.4.3
python  install
cd ..
# Install Setuptools
unzip setuptools-34.2.
cd setuptools-34.2.0
python  install
cd ..
# Install pip
tar xf pip-9.0.
cd pip-9.0.1
python  install
cd ..

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

# pip offline install
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. (python 2.7)

[root@ansible-wangao ansible]# ansible --version
ansible 2.3.0.0
 config file = /etc/ansible/
 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 doujinshi pip source
vim $HOME/.pip/

[global]
index-url = /simple/
[install]

trusted-host=

Windows installation of Python 2.

Download Python, e.g. 2.7.13

/downlo...

/ftp/py...

Note that the environment variable Add to Path is checked during installation.

Install python 2.7.13 which comes 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 after installing Python -m pip install --upgrade pip

# Replace pypi domestic source, running the following python code will automatically build the
import os

ini="""[global]
index-url = /simple/
[install]
trusted-host=
"""
pippath=["USERPROFILE"]+"\\pip\\"

if not (pippath):
  (pippath)

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

This is the whole content of this article.