CentOS7 Python2.7.5 upgrade 3.7.1

CentOS 7 in the default installation of Python, relatively low version (2.7.5), in order to use the new version 3.x, need to upgrade older versions. Because many basic commands, packages are dependent on older versions, such as: yum. So, when you update Python, we recommended not to delete the old version (old and new versions can coexist).

First, view the current python version

[root@d0c3d9dd14c1 /]# python -V
Python 2.7.5

Second, download and install the new package python

Into the python's official website (https://www.python.org), select the desired version. Here I chose the most current version Python3.7.1

[root@d0c3d9dd14c1 /]# yum install gcc gcc-c++ libffi-devel openssl-devel python-setuptools vim wget make sqlite-devel zlib* -y
[root@d0c3d9dd14c1 /]# wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz
[root@d0c3d9dd14c1 /]# tar xvf Python-3.7.1.tar.xz
[root@d0c3d9dd14c1 /]# cd Python-3.7.1
[root@d0c3d9dd14c1 /]# cd Python-3.7.1
[root@d0c3d9dd14c1 Python-3.7.1]# ./configure --with-ssl
[root@d0c3d9dd14c1 Python-3.7.1]# make
[root@d0c3d9dd14c1 Python-3.7.1]# make install

Note: I have access to information that, in the course of ./configure, if not add -with-ssl parameters, default software installation related to the ssl feature is not available,
just pip3 process requires ssl module, but because there is no specified, so this feature is not available.

Third, verify

[root@d0c3d9dd14c1 Python-3.7.1]# python -V
Python 2.7.5
[root@d0c3d9dd14c1 Python-3.7.1]# python3 -V
Python 3.7.1

Fourth, set as the default version 3.X

  View Python path in / usr / bin below. Python can see links is python 2.7, so execution is equivalent to execute python python 2.7.

[root@d0c3d9dd14c1 Python-3.7.1]# ls -al /usr/bin | grep python
lrwxrwxrwx 1 root root 7 Dec 5 01:36 python -> python2
lrwxrwxrwx 1 root root 9 Dec 5 01:36 python2 -> python2.7
-rwxr-xr-x 1 root root 7216 Oct 30 23:46 python2.7

The original python soft link Rename:

[root@d0c3d9dd14c1 Python-3.7.1]# mv /usr/bin/python /usr/bin/python.bak

The python link to python3:

[root@d0c3d9dd14c1 Python-3.7.1]# ln -s /usr/local/bin/python3 /usr/bin/python

 

Fifth, configure yum

After upgrading Python, due to the default python pointing python3, yum not working, yum need to edit the configuration file, then:
[root @ d0c3d9dd14c1 Python-3.7.1] # yum List
File "/ usr / bin / yum" , Line 30
the except the KeyboardInterrupt, E:

SyntaxError: invalid syntax
modify / usr / bin / yum and / usr / libexec / urlgrabber-ext -down, the # / usr / bin / python changed to # / usr / bin / python2.7, you can save out!!.

 

Sixth, install Django

[root @ d0c3d9dd14c1 Python - 3.7 . 1 ] # PIP3 install - upgrade Update # PIP PIP3 
[root @ d0c3d9dd14c1 Python - 3.7 . 1 ] # PIP3 install Django # install Django 
[root @ d0c3d9dd14c1 Python - 3.7 . 1 ] # Python - Django m - version # View Django version
 2.1 . 4 
[root @ d0c3d9dd14c1 Home] # mkdir MyBlog # to create a Django application directory 
[root @ d0c3d9dd14c1 Home] # cd MyBlog / 
[root @ d0c3d9dd14c1 MyBlog] # Django - ADMIN startproject MyBlog # create a Django APP
[root @ d0c3d9dd14c1 myblog] # cd MyBlog
[root @ d0c3d9dd14c1 myblog] # python manage.py migrate # migrate database 
[root @ d0c3d9dd14c1 myblog] # after python manage.py createsuperuser # migrate a database, create an administrative user so that you can use the Django admin interface 
[root @ d0c3d9dd14c1 myblog] Python manage.py the runserver # 0.0 . 0.0 : 8000

 


reference:

https://www.cnblogs.com/yard/p/10083843.html

 

Guess you like

Origin www.cnblogs.com/sandshell/p/11759213.html