python 3.6.5 in macos applications

Installed Python 3 On Mac OS X But It Still Use Python 2.7

Mac OS X has installed python by default, but the version is 2.7.10. It is a little old, so i decide to upgrade python to the newest version which is 3.6.5 now. But after install new version, when i open a terminal and run python, it still use python 2.7. This issue also exist in Windows and Linux. This article will tell you how to fix it.

1. Install Python 3.6.5.

  1. Go to python download page and click the related link to download.
    download python 3.6.5 installer
  2. After download, just double click the installer to install it until finish. Now the python new version has been installed successfully. You can see it in MacOS Applications folder.
    python 3.6.5 in macos applications
  3. You can also see the newly installed python bin folder has been added in PATH system environment variable when run set command in terminal.
    192:~ dev2qa$ set

2. Execute Python3.

  1. When you execute python command in terminal, you will find it still use the old version which is 2.7.
    192:~ dev2qa$ python
    Python 2.7.10 (default, Oct  6 2017, 22:29:07) 
  2. To use new python version, you need to run python3 in terminal.
    192:~ dev2qa$ python3
    Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 05:52:31) 
  3. To exit the python interaction console, just input command exit(). Then you can go back to terminal bash environment again.
    192:~ dev2qa$ python3
    Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 05:52:31) 
    [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> exit()
  4. To get current python version, just add uppercase V as the python command parameter like below.
    $ python -V
    Python 2.7.10
    $ python3 -V
    Python 3.7.3

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.