Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to switch Python versions in Terminal?

My Mac came with Python 2.7 installed by default, but I'd like to use Python 3.6.1 instead.

How can I change the Python version used in Terminal (on Mac OS)?

Please explain clearly and offer no third party version manager suggestions.

like image 245
heapoverflow Avatar asked Apr 11 '17 19:04

heapoverflow


People also ask

How do I switch between Python versions?

Yes, you should be able to switch between python versions. As a standard, it is recommended to use the python3 command or python3. 7 to select a specific version. The py.exe launcher will automatically select the most recent version of Python you've installed.

How do I use a different version of Python in terminal?

The default Python interpreter is referenced on Windows using the command py. Using the Command Prompt, you can use the -V option to print out the version. You can also specify the version of Python you'd like to run. For Windows, you can just provide an option like -2.7 to run version 2.7.


1 Answers

The simplest way would be to add an alias to python3 to always point to the native python installed. Add this line to the .bash_profile file in your $HOME directory at the last,

alias python="python3" 

Doing so makes the changes to be reflected on every interactive shell opened.

like image 129
Inian Avatar answered Sep 22 '22 22:09

Inian