Ubuntu upgrades Python from default 2.7 to version 3. *

Source: Internet
Author: User

Ubuntu upgrades Python from default 2.7 to version 3. *

Ubuntu upgrades Python from the default version 2.7 to version 3. * (we recommend that you use the Python version of the original system for Python Development)

Because many underlying components of Ubuntu use Python2. *, Python3 and Python2 are incompatible with each other, so you cannot uninstall Python2 at this time. You need to point the default Python to Python3.

First refresh the source sudo apt-get update

Then update the system sudo apt-get dist-upgrade.

Download the latest Python code from the ubuntu Terminal

Sudo apt-get install python3

The Python program just downloaded is installed in usr/local/lib/python3.5.

Cd/usr/local/lib

Ls-l

Pwd

Root@bkjia.com :~ # Cd/usr/local/lib
Root@bkjia.com:/usr/local/lib # ls-l
Total usage 8
Drwxrwsr-x 4 root staff 4096 19:55 python2.7
Drwxrwsr-x 3 root staff 4096 April 12 2017 python3.5
Root@bkjia.com:/usr/local/lib # pwd
/Usr/local/lib
Root@bkjia.com:/usr/local/lib #

We will first back up sudo cp/usr/bin/python/usr/bin/python_bak

Then run the command to delete the default python link file under the usr/bin/directory.

Run24pro@bkjia.com:/usr/local/lib $ cd/usr/local/lib
Run24pro@bkjia.com:/usr/local/lib $ cd/usr/bin/
Run24pro@bkjia.com:/usr/bin $ sudo cp/usr/bin/python/usr/bin/python_bak
Run24pro@bkjia.com:/usr/bin $ rm-rf python
Rm: Unable to delete 'python': insufficient Permissions
Run24pro@bkjia.com:/usr/bin $ sudo-I
Root@bkjia.com :~ # Rm-rf python
Root@bkjia.com :~ #

Creates a new connection for the default python compiler.

Ln-s/usr/bin/python3.5/usr/bin/python note: if you want to switch back to python2.7, first Delete the link and then ln-s/usr/bin/python2.7/usr/bin/python

Run24pro@bkjia.com:/usr/bin $ sudo-I
Root@bkjia.com :~ # Rm-rf python
Root@bkjia.com :~ # Cd/usr/bin/
Root@bkjia.com:/usr/bin # ln-s/usr/bin/python3.5/usr/bin/python
Ln: the symbolic link '/usr/bin/python' cannot be created: the file already exists.
Root@bkjia.com:/usr/bin # ln-s/usr/bin/python3.5/usr/bin/python
Ln: the symbolic link '/usr/bin/python' cannot be created: the file already exists.
Root@bkjia.com:/usr/bin # python
Python 2.7.13 (default, Nov 23 2017, 15:37:09)
[GCC 6.3.0 20170406] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> Quit ()
Root@bkjia.com:/usr/bin # rm-rf python
Root@bkjia.com:/usr/bin # ln-s/usr/bin/python3.5/usr/bin/python
Root@bkjia.com:/usr/bin # python
Python 3.5.3 (default, Nov 23 2017, 11:34:05)
[GCC 6.3.0 20170406] on linux
Type "help", "copyright", "credits" or "license" for more information.

Input python

Root@bkjia.com:/usr/bin # python
Python 3.5.3 (default, Nov 23 2017, 11:34:05)
[GCC 6.3.0 20170406] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

Successful!

If you have other problems and need to fix them, just download them again.

Sudo apt-get install -- reinstall python-minimal
Sudo apt-get install -- reinstall python2.7

Note:

If python3.5 is used, but after the fix, the previous pip, django, and others are all under python3, there will be some problems. Because of incompatibility.

In this case, it is recommended that you reinstall the system and then use python2.7. Do not upgrade the software, and install the corresponding version later. In this way, there will be no incompatibility issues.

Python decorators

Concurrent processing of things in Python

Install Vim8 in Ubuntu 16.04 and support Python3

Install Python3 in CentOS 6.4

"No module named yum" is unavailable due to Python upgrade"

Python network framework basic Twisted learning and detailed explanation

CentOS7 retain the default Python version and install and update Python2 and Python3 to coexist.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.