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)?


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.

| improve this answer | |
  • Any idea where such a file would be for each user? (would it be in a home directory or my own working directory?) or alternatively would running this within terminal change the python version in the current session? – hsnee Nov 17 '15 at 15:59
  • 1
    Normally you can find the .bashrc in your user account home directory i.e. /home/username/.bashrc. You can edit the file using vi by simply typing vi ~/.bashrc – nuwandame Nov 18 '15 at 4:43

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.,


Taken from linfo.org

| improve this answer | |

In your program if you mention #!/usr/bin/python2.6 as the first line then your program will consider python 2.6 as its runtime environment. And similarly if you mention python2.7 it will consider from python2.7.

If you want to access python from terminal then you can give python2.7 at terminal and you will get into it.

| improve this answer | |
  • 1
    NB: #!/usr/bin/env python2.7 may work better than directly inputting the path to Python, and makes your code more portable. – user201155 Nov 17 '15 at 18:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.