4

I am using ubuntu 14.04 and I have a program that depends on python 2.7 and does not support any of python 3.x. Ubuntu 14.04 comes with python3.4 by default. I would like to know if there is a possibility to make my program uses python2.7 instead of the default version. I thought about uninstalling python3.4, but I think it is not a good idea as some other programs may depends on it.

Thanks

8
  • 2
    Python 2.7 is the default in 14.04.
    – Timo
    Dec 3, 2014 at 14:52
  • When I type $python it appears python 3.4
    – Aymen
    Dec 3, 2014 at 14:54
  • Do you have your python 2.7 installed? So if you run 'python2.7' it gives you the python shell...
    – Andor
    Dec 3, 2014 at 14:56
  • After I installed python2.7 I can get python2.7 shell when I type $python. Before only python3.4 was installed. So can I assume now that a program which depends on python2.7 will run without problems with both versions coexisting?
    – Aymen
    Dec 3, 2014 at 15:01
  • 1
    Jacob you have right. Depending on shebang defining version, present in python script, the appropriate python version will be used providing it is installed of course.
    – Aymen
    Dec 3, 2014 at 15:28

2 Answers 2

4

Check your ~/.bashrc and/or .bash_aliases to find if you have any kind of alias like this:

alias python=python3

Change it accordingly to python2.7

4
  • I don't have .bash_aliases file and .bashrc file does not contain an alias for python. Shall I add it?
    – Aymen
    Dec 3, 2014 at 15:06
  • You can do it for convenience. Also, do an: 'ls -l /usr/bin/python' to check where it's linked.
    – Andor
    Dec 3, 2014 at 15:12
  • /usr/bin/python links to python2.7. But, what I would like to do is that one program use python while others continue to use python3.4. I assume that when a program depending on python3.4 is executed it will call soft link python3 not python. Is my assumption correct?
    – Aymen
    Dec 3, 2014 at 15:19
  • Depends on how it's programmed. Check stackoverflow.com/questions/11170827/…
    – Andor
    Dec 3, 2014 at 15:35
2

Normally, in Ubuntu, python defaults to python2. So you probably have a

#!/usr/bin/env python3 
# 

or similar in the top of your script. Either if this is the case or if you have changed the defaults, in the header of your program, change

#!/usr/bin/env python
# 

(or the more probable python3) to

#!/usr/bin/env python2
# 

In standard Ubuntu, python should automatically point to python2:

[romano:~/tmp] % ls -l /usr/bin/python
lrwxrwxrwx 1 root root 9 jul 22 09:49 /usr/bin/python -> python2.7

so normally the above thing should not be needed. But python2 and python3 points respectively to the standard version of version 2 and 3, so if you explicitly want one version, simply tell it.

Not the answer you're looking for? Browse other questions tagged .