Choose Your Python Version
How to find out your Python version
In our instructions, we typically say to run Python scripts with the following command format:
python3 <scriptname.py>
python3
is actually a symbolic link to a specific Python interpreter. Which one? You can find out by entering:
python3 --version
or use the following command to see how the symbolic link points to the a specific interpreter:
ls -l /usr/bin/python3
What if I want to use a different version?
One easy way to accomplish this (and reduce your typing requirements), is to create an alias. You can open the file ~/.bashrc
in your favorite text editor and add the following line at the end of the file:
alias py="/usr/bin/python3.7"
Or without a text editor, just enter this command :
echo "\nalias py=\"/usr/bin/python3.7\n\"" > ~/.bashrc
After editing your ~/.bashrc
, you'll need to reload it:
source ~/.bashrc
Now, whenever you enter py
, your shell will interpret it as a direct call to your python interpreter of choice! And your fingers can rest easy without typing out python3
every time ;)
# Look ma, less typing!
py <scriptname.py>