In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to modify the default Python version on CentOS 6.x. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
A recent problem is that there is a feature that you want to implement on a variety of servers, and the system versions on the servers may be different, from CentOS 6.x to CentOS 7.x.
It is important to note that the Python version on CentOS 6.x is 2.6.x, while the Python version on CentOS 7.x is 2.7.x, which means that the functionality I want to implement is compatible with both versions of the system.
You might say, what's wrong with this? just pay attention when you write it yourself.
In fact, things are not that easy, I want to implement the function is based on a framework for customization, need to modify a lot of framework code. There are different versions of this framework on different Linux versions, and there are great differences. I once thought of installing the framework into the same version in CentOS 6.x and CentOS 7.x, but finally failed and could not be installed, because the high version requires Python2.7, while there is only Python2.6 on CentOS 6.x.
This historical problem has been left to the present, as this function affects a lot of code, if you want to customize the two versions of the framework, it will take a lot of time, in order not to maintain the two versions, to avoid wasting extra energy to adapt, I decided to upgrade the default Python2.6 on CentOS 6.x to Python2.7, once and for all.
The following is the whole upgrade process, despite the simple steps, there are a lot of holes behind these streamlined steps, after I stepped on them, you can use them directly.
1. First confirm the default Python version on your machine
$python-VPython 2.6.6$ whereis pythonpython: / usr/bin/python / usr/bin/python2.6 / usr/lib/python2.6 / usr/lib64/python2.6 / usr/local/bin/python / usr/include/python2.6 / usr/share/man/man1/python.1.gz
2. Since we will use compilation and installation, we need to install gcc and some toolkits.
Be sure to install them all, or you will find that a lot of python tools are not available.
For example, without installing zlib, you will not be able to install setuptools, without openssl and openssl-devel, you will not be able to use pip tools, and so on.
$yum install gcc-y $yum groupinstall "Development tools" $yum install zlib-devel bzip2-devel openssl openssl-devel ncurses-devel sqlite-devel-y
If you do not follow my steps to install, you later use when there are a variety of problems, do not panic, just come back here, put the uninstalled packaging, after the installation is complete, you need to go to step 4 to recompile and install Python.
3. Download the latest Python2.7.x installation package, extract it and enter the specified directory
$wget https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz$ tar zxvf Python-2.7.14.tgz$ cd Python-2.7.14
4. Configure, compile, install
#-- prefix specifies the path to python installation $. / configure-- prefix=/usr/local/python/python2.7$ make$ make install
After the execution of the. / configure command, create a file creating Makefile, which can be used by the following make command. After executing make install, the program will be installed in the directory we specified.
Configure is an executable script that has many options. Use the command. / configure-help to output a detailed list of options under the source path to be installed. The-- prefix option is the path to configure the installation. If this option is not configured, the executable file is placed at / usr/local/ bin by default, the library file is placed at / usr/local/lib by default, the configuration file is placed at / usr/local/etc by default, and other resource files are placed at / usr/local/ share. If you configure-- prefix, such as:. / configure-- prefix=/usr/local/test can put all resource files in the path of / usr/local/test without clutter.
Another benefit of using the-- prefix option is to uninstall or migrate the software. When an installed software is no longer needed, simply delete the installation directory and uninstall the software cleanly; migrate the software simply by copying the entire directory to another machine (the same operating system). Of course, to uninstall the program, you can also use make uninstall once in the original make directory, but only if the make file has specified uninstall.
5. View the Python version of the system at this time
$python-VPython 2.6.6
If you are still looking at Python version 2.6.6, please continue to step 6.
6. Modify the default Python version of the system
Check the newly installed version of Python, the Python version of the current system, and change the Python that the system points to from 2.6.x to 2.7.x, and check the Python version of the current system again, which has been changed to 2.7.x.
# this is the Python$/usr/local/bin/python2.7-VPython 2.7.1 installation that we just installed. This is the system default Python$/usr/ bin/python-VPython 2.6.backup the original Python file $mv / usr/bin/python / usr/bin/python.bak# to establish a soft link, and use the python2.7 we just installed as the default version of the system ln-s / usr/local/bin/python2.7 / usr/bin/python# to check the Python version again. Successfully switched over $python-VPython 2.7.14
7. Reassign the Python version of yum
Above we changed the default Python version of the system, because the yum of CentOS 6.x is based on Python2.6, in order not to affect the use of yum, we need to point the yum to the python2.6 version separately.
Edit: vim / usr/bin/yum
Change / usr/bin/python to / usr/bin/python2.6
#! / usr/bin/python2.6
8. Install setuptools and pip
Pip is the installation tool for python, and many common tools for python can be installed through pip. To install pip, first install setuptools.
# download setuptools$ wget https://pypi.python.org/packages/ff/d4/209f4939c49e31f5524fa0027bf1c8ec3107abaf7c61fdaad704a648c281/setuptools-21.0.0.tar.gz#md5=81964fdb89534118707742e6d1a1ddb4
Similarly, install:
$tar vxf setuptools-21.0.0.tar.gz $cd setuptools-21.0.0$ python setup.py install
After the installation is complete, download pip.
# download pipwget https://pypi.python.org/packages/41/27/9a8d24e1b55bd8c85e4d022da2922cb206f183e2d18fee4e320c9547e751/pip-8.1.1.tar.gz#md5=6b86f11841e89c8241d689956ba99ed7
Similarly, install:
$tar vxf pip-8.1.1.tar.gz $cd pip-8.1.1$ python setup.py install
After the installation is complete, execute pip list to check the installed package, or you can try installing the third-party package pip install requests to see if it works properly.
This is the end of this article on "how to modify the default Python version on CentOS 6.x". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.