1

on Ubuntu 14.04 has python-3, python-2.7 and python is linked to python-2.7 by default. I have to run python-3 code on ubuntu -14.04. Can I modify /usr/bin/python link to python3? Any idea?

Thanks

mrudula
  • 477
  • 5
  • 9
  • 17
  • check sudo update-alternatives --list python If multiple versions are listed, you cen set which one to use with sudo update-alternatives --set python – Charles Green Nov 12 '15 at 16:33
  • sudo update-alternatives --list python tried above command showing no alternatives with below error: update-alternatives: error: no alternatives for python – mrudula Nov 12 '15 at 16:44

1 Answers1

7

Don't do that.

A lot of things will (probably) break if you change the default python interpreter to python3.

The switch is not a simple one --- although by 16.04 I think that all the system scripts will be python3, it will probably not switched even then (thanks @florian-deisch). Other distros, like Arch, did the switch, but I am not sure if this is a good thing, given that there is a PEP explicitly suggesting the contrary...

Simply use

#!/usr/bin/env python3

as the "shebang" line (first line) of the scripts that you want to be run by python3.

muru
  • 197,895
  • 55
  • 485
  • 740
Rmano
  • 31,947
  • 2
    Most likely /usr/bin/python will still not point to python3 in 16.04 as recommended by PEP 0394 – Florian Diesch Nov 12 '15 at 17:03
  • 2
    @FlorianDiesch Indeed. for the time being, all distributions should ensure that python refers to the same target as python2 . – gertvdijk Nov 12 '15 at 17:04
  • 3
    The PEP came about because Arch made Python 3 the default. – muru Nov 12 '15 at 17:15
  • I can not make virtual environment as my scripts are running on Embedded / target board,which has Ubuntu 14.04 with minimal package support. As I'm running my application on embedded board, i have memory constraint. So i can not install many packages, which may lead to insufficient memory problem. Any other idea / way? – mrudula Nov 12 '15 at 18:36
  • Any other way so that i can point python to python-3. I have ported my application to python-3. Will it run with both python-2 and python-3? How to isolate python-2 dependencies and make sure it is running only on python-3? Please do share your views. I'm Stuck..!! – mrudula Nov 12 '15 at 18:38