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.
- Go to python download page and click the related link to download.
- 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.
- 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 PATH=/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
2. Execute Python3.
- 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)
- 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)
- 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()