Using different version of Python
I am using a server that I do not have admin access on. There are several versions of pythons installed. Say one is in /some/home/directory/Python2.6/
and the other in /some/home/directory/Python2.7/
.
Is there a simple way of changing the python version in terminal temporarily, without changing the default version of python, and without requiring root access (all the answers I have found so far does/requires one of those conditions)?
Solution 1:
To change the python version for your terminal session you can create an alias in your .bashrc file then re-login.
alias python='/usr/bin/python3.4'
The link to the following article provides detailed instructions to change to an alternate Python version per user session.
Solution 2:
My recommendation would be to use an alias to "override" the python command.
An alias can be created with the same name as the core name of a command (i.e., a command without any options or arguments). In such case, it is the alias that is called (i.e., activated) first when the name is used, rather than the command with the same name. For example, an alias named ls could be created for the command ls -al as follows:
alias ls="ls -al"
ls is a commonly used command that by default lists the names of the files and directories within the current directory (i.e., the directory in which the user is currently working). The -a option instructs ls to also show any hidden files and directories, and the -l option tells it to provide detailed information about each file and subdirectory.
Such an alias can be disabled temporarily and the core command called by preceding it directly (i.e., with no spaces in between) with a backslash, i.e.,
\ls
Taken from linfo.org