"I hope to improve my English in the course of blogging, maybe?" 】
"Is it possible to improve my poor 中文版 by writting blog? I don ' t know. "
Recently started learning Python.
Python fire so long, I finally still kneeling to lick it, I am a follower of the people, learning C, C #, JAVA, PHP, without an exception to taste, do not know I this pair of myopic eyes, confirmed the eyes are not right, I hope Python is it.
By the way, the gods will stop learning, I can't keep up.
I want to learn python from now on.
Python is so popular that I Cann ' t turn a blind eye and finally I put my knees to it. I am a following boy (maybe a uncle), I had learned a lot of languages, such as C C + + JAVA PHP, none of them can be C Ontinued. I cann ' Be sure python are right-me, especially I am shortsighted, but I still hope Python is my correct choice.
By the-the-I begged all of the big-gods, stoped, I cann ' t catch up!
Anyway, CentOS7 has installed the python2.7 version by default, and the Yum command and other uses it, so we can't remove the python that the system installed by default.
It is only necessary to install the desired version of the system (usually a later version of the update) and to coexist with the default version.
The specific operation steps, probably can be divided into the following several:
1. Check if Python is installed on the system, and if the version is incorrect, backup;
2. Modify the Yum configuration file;
3. Install the new version of Python;
4. Modify Python's soft link file;
Let's get back on track , CentOS7 had installed python2.7 by default, and Yum command or others would use to it, so W e Cann ' t remove it.
So, we just has to install the right version of the Python "What we Want" (usually more higher and more newer version), and With the default version on the same time in the System OS.
As follows:
1. Be sure the system have Python or not, if yes and the version isn ' t we want, backup it;
2. Edit the Configure file of the Yum command;
3. Install the new version of Python;
4. Change the link files of python;
First, see if Python is already installed (this machine is the CentOS Linux release 7.5.1804, minimized installation)
1. Using Python- V command to see if Python is installed:
# python-v
python 2.7.5
2. It is clear that Python's 2.7.5 version is installed, which is not what I need, so make a backup of this version:
# which Python
& nbsp /usr/bin/python
# Cd/usr/bin
# Ls-la python*
&NB Sp lrwxrwxrwx. 1 root root 7 June 15:14 Python--python2
lrwxrwxrwx. 1 root root 9 June 15:14 Python2-python2.7
-rwxr-xr-x. 1 root root 7216 Apr one 15:36 PYT hon2.7
3. You can see that the Python command of the system actually executes the python2.7, we back up this link file
# mv Python Python.bak
Second, modify the Yum configuration file
1. View Yum files
# ls-la/usr/bin/yum*
& nbsp -rwxr-xr-x. 1 root root 801 Apr 20:58/usr/bin/yum
2. View Urlgrabber file
# ls-la/ Usr/libexec/urlgrabber-ext-down
-rwxr-xr-x. 1 root root 2603 26 2013/usr/libexec /urlgrabber-ext-down
3. Change the file header of the above file with vim and modify the #!/usr/bin/python to #!/usr/bin/python2
# Vim /usr/bin/yum
# Vim /usr/libexec/urlgrabber-ext-down
Third, install the new version of Python
1. Install the compilation environment and the dependencies that may be used
# yum Groupinstall "Development Tools"
# yum install-y ncurses-libs zlib-devel mysql-devel bzip2-devel o Penssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
& nbsp 2. Download the latest version (currently the latest is 3.6.5),: Https://www.python.org/downloads/source
# wget https:// WWW.PYTHON.ORG/FTP/PYTHON/3.6.5/PYTHON-3.6.5.TAR.XZ
3. Compile and install
# tar-xvf& nbsp PYTHON-3.6.5.TAR.XZ
# cd python-3.6.5
# ./ Configure--prefix=/usr/local/python3.6--enable-optimizations
# make && make Install
NOTE:--prefix, installation path,--enable-optimizations, optimization option, approximately 10% performance improvement (online parlance, not verified)
Iv. Modification of soft links
1. Creating a system Soft link
# ln-s/usr/local/python3.6/bin/python3.6/usr/bin/python
# ln-s/usr/local/python3.6/bin/pip3.6/usr/bin/pip
2. View
# python-v
# pip-v
The article ends here.
Part 1. Make sure it is had installed Python. ( My system is CentOS Linux release 7.5.1804, minimal)
1.use command python-v to show Python version:
# python-v
Python 2.7.5
2.obviously,there is installed Python 2.7.5,so backup it:
# which Python
/usr/bin/python
# Cd/usr/bin
# Ls-la python*
lrwxrwxrwx. 1 root root 7 June 15:14 Python--Python2
lrwxrwxrwx. 1 root root 9 June 15:14 Python2-python2.7
-rwxr-xr-x. 1 root root 7216 Apr 15:36 python2.7
3.we can see this system use Python2.7,we can backup the link file
# mv Python Python.bak
Part 2. Edit Yum config file
1.cat all yum files
# ls-la/usr/bin/yum*
-rwxr-xr-x. 1 root root 801 Apr 20:58/usr/bin/yum
2.cat urlgrabber File
# Ls-la/usr/libexec/urlgrabber-ext-down
-rwxr-xr-x. 1 root root 2603 2013/usr/libexec/urlgrabber-ext-down
3.use Vim Modify the head of above files, change #!/usr/bin/python to #!/usr/bin/python2
# Vim/usr/bin/yum
# Vim/usr/libexec/urlgrabber-ext-down
Part 3. Install New Python version
1.Install compile environment and some possible dependences package
# yum Groupinstall "Development Tools"
# yum install-y ncurses-libs zlib-devel mysql-devel bzip2-devel openssl-devel ncurses-devel Sqlite-devel Read Line-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
2.download The newest version of Python (the newest is 3.6.5), download Url:https://www.python.org/downloads/source
# wget Https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz
3.Installing
# TAR-XVF Python-3.6.5.tar.xz
# CD Python-3.6.5
#./configure--prefix=/usr/local/python3.6--enable-optimizations
# make && make install
ps:--prefix,install path;--enable-optimizations,maybe optimization,about 10% performent Improvement (This said by Internet,no verification)
Part 4. Create link files
1.create Link Files
# ln-s/usr/local/python3.6/bin/python3.6/usr/bin/python
# ln-s/usr/local/python3.6/bin/pip3.6/usr/bin/pip
2.make sure
# python-v
# pip-v
Over.
CentOS7 Installing Python3