Modify the Python version (for Mac OS X)

Source: Internet
Author: User

Python 2.7 is preinstalled on Mac OS X 10.8 and later, but it's not as easy for Windows to modify the Python version on Mac (Unix-like OS). The goal of this article is to upgrade the Python 2.7 that comes with Mac to 3.4.

Body part:

  1. Download and install the new Python
    • https://www.python.org/
  2. Copy the new Python to the system directory and modify the file owner
      • sudo mv/library/frameworks/python.framework/versions/3.4//system/library/frameworks/python.framework/versions
      • sudo chown-r root:wheel/system/library/frameworks/python.framework/versions/3.4/
  3. Modify a Python connection file
    1. Modifying the current Connection file
      • sudo ln-s/system/library/frameworks/python.framework/versions/3.4/system/library/frameworks/python.framework/ Versions/current
    2. Delete python-related connection files under/usr/bin/
      • If the files themselves are not connection files, they must be deleted before the corresponding connection files can be created. Otherwise, the file exists will be prompted
      • /usr/bin/pydoc
      • /usr/bin/python
      • /usr/bin/pythonw
      • /usr/bin/python-config
    3. Re-create the corresponding connection file under/usr/bin/
      • sudo ln-s/system/library/frameworks/python.framework/versions/3.4/bin/pydoc3/usr/bin/pydoc
      • sudo ln-s/system/library/frameworks/python.framework/versions/3.4/bin/python3/usr/bin/python
      • sudo ln-s/system/library/frameworks/python.framework/versions/3.4/bin/python3/usr/bin/pythonw
      • sudo ln-s/system/library/frameworks/python.framework/versions/3.4/bin/python3.4m-config/usr/bin/python-config
  4. Modify. bash_profile, specify user variables (requires restart terminal to take effect)
    • Path=/system/library/frameworks/python.framework/versions/3.4/bin:${path}
    • Export PATH
  5. Enter Python-v view, which should be the modified version.

There are two places worth noting:

  1. do not remove python! from your Mac Because the Mac or third-party software may be referenced. Using the Ls-l/system/library/frameworks/python.framework/versions, you can see that there are 2.3 to 2.7 versions of the connection file that confirm this. Online search out of the Chinese post is probably because of the reasons for the copy and paste, all first delete the python from the same, I do not know what mentality. Accompanying python.org:
    • The apple-provided build of Python is installed In/system/library/frameworks/python.framewor K And/usr/bin/python, respectively. You should never modify or delete these, as they is apple-controlled and is used by apple-or Third-party software. Remember that if you choose to install a newer Python version from python.org and you'll have both different but functi Onal Python installations on your computer, so it'll be a important that your paths and usages is consistent with what yo U want to do.
  2. Python 2.7,/usr/bin/python and/usr/bin/pythonw together point to/system.../versions/3.4/bin/python3, in my newly installed Python version of bin/ The next is no pythonw this command. Accompanying original text:
    • With older versions of Python, there are one Mac OS X Quirk that's need to being aware of:programs that talk to the Aqua WI Ndow Manager (in the other words, anything, and a GUI) need to is run in a special the. Use PYTHONW instead of the python to start such scripts. With the Python 3.4, you can use either Python or pythonw.

Because I am in contact with Linux and Python for a short time, there are errors or can be more streamlined steps to welcome the proposed to discuss. _ (: 3"∠) _

Modify the Python version (for Mac OS X)

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.