Centos installed by default in version 7 Python 2.7, and now many people are using a version of 3.x, and therefore need to know how to upgrade from Python2.7 next to Python 3.6.
When a virtual machine is installed, the network is disconnected will first encounter an error message "yum Error: Can not find a valid baseurl for repo: base / 7 / x86_6", then
first
cd / etc / sysconfig / network- scripts /
to find similar ifcfg-exxx similar files (each file name is not the same machine, this machine is my ifcfg-ens33), editing with vi look, the ONBOOT = no, instead ONBOOT = yes
then
service network restart
Then through the network, yum command will Haoshi, and then began to upgrade Python
1, switch to the directory / usr / local / src, acquired from the Python to the official website Python3 package, execute the command line: wget
CD / usr / local / the src
wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
2, decompressing
-xzf Python3.6.3.tgz tar
3, create a directory under / usr / local path --python3
mkdir / usr / local / to python3
. 4, compiler installation, row stripe Run
/usr/local/src/Python-3.6.3 cd
./configure --prefix = / usr / local / python3
the make All
the make install
to the last command execution if an error is encountered: zipimport.ZipImportError: can not decompress data ; zlib not available
From the error message, we can see that zlib package system has been installed, and the reason given is because they can not develop zlib libraries when compiling the installation.
centos system, zlib developers link library package is "zlib-devel", so we only need to install the package to pass yum:
sudo yum -y install zlib-devel
before continuing make install
5, enter the absolute path for the installation, check whether the installation was successful
-V /usr/local/python3/bin/python3.6
6, viewing environment variable PATH in order to find the default when starting python.
Execute the command: echo $ PATH
7, modify the soft connection, when you start pointing python3.6 python
python A. previous backup
execute the command: mv / usr / bin / python /usr/bin/python2.7.5 ( please inquire their own python version)
B. Modify soft connection
Run: ln -s / usr / local / python3 / bin / python3 / usr / bin / python
C. Check python version: Execute the command: python
Or python -V, pip -V
8, yum modify files because after the upgrade version, yum will error:
execute the command: sudo vim / usr / bin / yum
9, when installing the software will report an error: modify the file
vi /usr/libexec/urlgrabber-ext-down
The first line read:! # / Usr / bin / python2.7 (2.7 version, change according to their own version!)