"Go" Mac upgrade python2.7 to python3.6

Source: Internet
Author: User

1. Preface

Mac system comes with python2.7, the purpose of this article is to upgrade your own Python to version 3.6.
Online there are many of the practice is to let python2.7 and python3.x two versions coexist, bloggers do not know, is the two version of coexistence, or direct upgrade, so readers should carefully choose the method.

2. Close the rootless mechanism

Because the python2.7 under Mac is installed in the/system directory by default. However, ~~~mac has a rootless mechanism that is not allowed to be modified directly under/system by default. Therefore, the rootless mechanism should be closed first.

Ways to turn off the rootless mechanism:
Shut down:
1). Restart the computer, press and hold command+r during restart to enter recovery mode
2). Open terminal, type: csrutil disable
3). Restart your computer

If you want to open the rootless mechanism later, the method is as follows:
Open:
1). Restart the computer, press and hold command+r during restart to enter recovery mode
2). Open terminal, type: Csrutil enable
3). Restart your computer

3. Download and install python3.6

From official website https://www.python.org/downloads/
Download the pkg version and install it. Install the default path, which will be installed in the/library/frameworks/python.framework/versions/directory

4. Delete python2.7
sudo rm -R /System/Library/Frameworks/Python.framework/Versions/2.7
    • 1
5. Mobile python3.6

Install the python3.6 into the/system/library/frameworks/python.framework/versions/directory:

sudo mv /Library/Frameworks/Python.framework/Versions/3.6 /System/Library/Frameworks/Python.framework/Versions
    • 1
6. Modify the group to which the file belongs

Set group to wheel, the original system comes with this is the case.

sudo chown -R root:wheel /System/Library/Frameworks/Python.framework/Versions/3.6
    • 1
7. Update the current link

In the versions directory there is a current link, is pointing to the present version of Python, the original point to the system comes with the Python2.7, we delete it, link is invalid, so need to re-link

sudo rm /System/Library/Frameworks/Python.framework/Versions/Currentsudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.6 /System/Library/Frameworks/Python.framework/Versions/Current
    • 1
    • 2
8. relink the executable file

1) First delete the original execution file of the system

sudo rm /usr/bin/pydocsudo rm /usr/bin/pythonsudo rm /usr/bin/pythonwsudo rm /usr/bin/python-config
    • 1
    • 2
    • 3
    • 4

2) Create a new link

sudo ln -s/system/ Library/frameworks/python.framework/versions/3.6/bin/pydoc3. 6/usr/bin/pydocsudo ln -s/system/library/frameworks/ Python.framework/versions/3.6/bin/python3. 6/usr/bin/pythonsudo ln -s/system/library/frameworks/ Python.framework/versions/3.6/bin/pythonw3. 6/usr/bin/pythonwsudo ln -s/system/library/frameworks/ Python.framework/versions/3.6/bin/python3. 6m-config/usr/bin/python-config            
    • 1
    • 2
    • 3
    • 4
9. Update the. bash_profile file

The default Bash_profile Python bin is pointing to/library/frameworks/python.framework/versions/3.6/bin. To be changed to the/system/directory

for Python 3.6# The orginal version is saved in .bash_profile.pysavePATH="/System/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"export PATH
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

I don't have a. Bash_profile this file by default, I created it directly.

10. Uninstalling the pkg installed python3.6

This step does not, when using the PIP3 command or error (it is connected to the/library/directory by default PIP3 command, but in fact should be found in the/system/library/directory). The blogger dropped the pit for a long time.

I use Cleanapp this software to uninstall the original pkg installed python3.6, installed in the two software are uninstalled.

11. Testing

On the command line, view the version and location with Pip-v and Pip3-v. Enter with Python.

Upgrade python2.7 to python3.6 under Mac, upgrade successfully.

Reference:
Http://www.jianshu.com/p/94a69ef2f2ef
Http://jingyan.baidu.com/article/14bd256e39b63dbb6d261289.html

"Go" Mac upgrade python2.7 to python3.6

Related Article

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.