James John – Software Engineer

Setting Python3 as your Default Shell Python in Ubuntu

Default Ubuntu Python package version is 2.7, while in my Python class I use 3.4 and everything I keep typing python3 whenever I want to run python.

Want to turn 3.4 to your default? Easy, BASH made this available by providing space for aliases in the config. Aliases is not only for this function, I can define donjajo as alias of ls so now we are gonna re-define python to python3. Open your terminal and type this

$ nano ~/.bashrc

Then add to the last line of the file

 alias python=python3

Save and exit. Close the terminal and reopen for the changes to take effect.

pyBut for developement purpose you want your Python code to be interpretted with Python 3 even if the person has Python 2 as his default, add this to the beginning of your code

#!/usr/bin/python3

I hope this helps 🙂

James John

Software Engineer