How to make 'python' program command execute Python 3?











up vote
247
down vote

favorite
75












The python program command executes Python 2. Python 3 can be executed using the python3 command. How can Python 3 be executed using the python command?










share|improve this question




















  • 25




    Just a warning: Do not attempt to change the /usr/bin/python symlink to point to python3 instead of 2.7. Many programs available in the Ubuntu repos require /usr/bin/python to be compatible to python 2.x.
    – soulsource
    Jul 17 '13 at 8:17






  • 1




    Ah, now I got what you meant with upgrade... Actually the Ubuntu developers are working on that: wiki.ubuntu.com/Python/3 "It is a release goal for Ubuntu 14.04 LTS to have only Python 3 on the desktop CD images."
    – soulsource
    Jul 17 '13 at 8:45






  • 1




    On another note, anyone coming here because they are trying to learn about making Python 3 their default, may instead find use in researching virtual environments (e.g. virtualenv) or containers (e.g. LXC or Docker).
    – Kevin
    Sep 13 '16 at 19:38






  • 1




    In reference to soulsource’s warning at the top see PEP 394 which standardises naming conventions for coexisting Python executables and on which Python programmers and package maintainers do (and should) rely.
    – David Foerster
    Jun 25 at 11:26








  • 1




    @wjandrea, yes even in a virtual environment, python should be kept as meaning python2. I meant my comment as a way to have an application specific Python version instead of trying to work around the system's Python.
    – Kevin
    Dec 5 at 18:57















up vote
247
down vote

favorite
75












The python program command executes Python 2. Python 3 can be executed using the python3 command. How can Python 3 be executed using the python command?










share|improve this question




















  • 25




    Just a warning: Do not attempt to change the /usr/bin/python symlink to point to python3 instead of 2.7. Many programs available in the Ubuntu repos require /usr/bin/python to be compatible to python 2.x.
    – soulsource
    Jul 17 '13 at 8:17






  • 1




    Ah, now I got what you meant with upgrade... Actually the Ubuntu developers are working on that: wiki.ubuntu.com/Python/3 "It is a release goal for Ubuntu 14.04 LTS to have only Python 3 on the desktop CD images."
    – soulsource
    Jul 17 '13 at 8:45






  • 1




    On another note, anyone coming here because they are trying to learn about making Python 3 their default, may instead find use in researching virtual environments (e.g. virtualenv) or containers (e.g. LXC or Docker).
    – Kevin
    Sep 13 '16 at 19:38






  • 1




    In reference to soulsource’s warning at the top see PEP 394 which standardises naming conventions for coexisting Python executables and on which Python programmers and package maintainers do (and should) rely.
    – David Foerster
    Jun 25 at 11:26








  • 1




    @wjandrea, yes even in a virtual environment, python should be kept as meaning python2. I meant my comment as a way to have an application specific Python version instead of trying to work around the system's Python.
    – Kevin
    Dec 5 at 18:57













up vote
247
down vote

favorite
75









up vote
247
down vote

favorite
75






75





The python program command executes Python 2. Python 3 can be executed using the python3 command. How can Python 3 be executed using the python command?










share|improve this question















The python program command executes Python 2. Python 3 can be executed using the python3 command. How can Python 3 be executed using the python command?







python python3






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 23 '17 at 15:31









Alex Willison

1176




1176










asked Jul 17 '13 at 8:04









Giri

1,378289




1,378289








  • 25




    Just a warning: Do not attempt to change the /usr/bin/python symlink to point to python3 instead of 2.7. Many programs available in the Ubuntu repos require /usr/bin/python to be compatible to python 2.x.
    – soulsource
    Jul 17 '13 at 8:17






  • 1




    Ah, now I got what you meant with upgrade... Actually the Ubuntu developers are working on that: wiki.ubuntu.com/Python/3 "It is a release goal for Ubuntu 14.04 LTS to have only Python 3 on the desktop CD images."
    – soulsource
    Jul 17 '13 at 8:45






  • 1




    On another note, anyone coming here because they are trying to learn about making Python 3 their default, may instead find use in researching virtual environments (e.g. virtualenv) or containers (e.g. LXC or Docker).
    – Kevin
    Sep 13 '16 at 19:38






  • 1




    In reference to soulsource’s warning at the top see PEP 394 which standardises naming conventions for coexisting Python executables and on which Python programmers and package maintainers do (and should) rely.
    – David Foerster
    Jun 25 at 11:26








  • 1




    @wjandrea, yes even in a virtual environment, python should be kept as meaning python2. I meant my comment as a way to have an application specific Python version instead of trying to work around the system's Python.
    – Kevin
    Dec 5 at 18:57














  • 25




    Just a warning: Do not attempt to change the /usr/bin/python symlink to point to python3 instead of 2.7. Many programs available in the Ubuntu repos require /usr/bin/python to be compatible to python 2.x.
    – soulsource
    Jul 17 '13 at 8:17






  • 1




    Ah, now I got what you meant with upgrade... Actually the Ubuntu developers are working on that: wiki.ubuntu.com/Python/3 "It is a release goal for Ubuntu 14.04 LTS to have only Python 3 on the desktop CD images."
    – soulsource
    Jul 17 '13 at 8:45






  • 1




    On another note, anyone coming here because they are trying to learn about making Python 3 their default, may instead find use in researching virtual environments (e.g. virtualenv) or containers (e.g. LXC or Docker).
    – Kevin
    Sep 13 '16 at 19:38






  • 1




    In reference to soulsource’s warning at the top see PEP 394 which standardises naming conventions for coexisting Python executables and on which Python programmers and package maintainers do (and should) rely.
    – David Foerster
    Jun 25 at 11:26








  • 1




    @wjandrea, yes even in a virtual environment, python should be kept as meaning python2. I meant my comment as a way to have an application specific Python version instead of trying to work around the system's Python.
    – Kevin
    Dec 5 at 18:57








25




25




Just a warning: Do not attempt to change the /usr/bin/python symlink to point to python3 instead of 2.7. Many programs available in the Ubuntu repos require /usr/bin/python to be compatible to python 2.x.
– soulsource
Jul 17 '13 at 8:17




Just a warning: Do not attempt to change the /usr/bin/python symlink to point to python3 instead of 2.7. Many programs available in the Ubuntu repos require /usr/bin/python to be compatible to python 2.x.
– soulsource
Jul 17 '13 at 8:17




1




1




Ah, now I got what you meant with upgrade... Actually the Ubuntu developers are working on that: wiki.ubuntu.com/Python/3 "It is a release goal for Ubuntu 14.04 LTS to have only Python 3 on the desktop CD images."
– soulsource
Jul 17 '13 at 8:45




Ah, now I got what you meant with upgrade... Actually the Ubuntu developers are working on that: wiki.ubuntu.com/Python/3 "It is a release goal for Ubuntu 14.04 LTS to have only Python 3 on the desktop CD images."
– soulsource
Jul 17 '13 at 8:45




1




1




On another note, anyone coming here because they are trying to learn about making Python 3 their default, may instead find use in researching virtual environments (e.g. virtualenv) or containers (e.g. LXC or Docker).
– Kevin
Sep 13 '16 at 19:38




On another note, anyone coming here because they are trying to learn about making Python 3 their default, may instead find use in researching virtual environments (e.g. virtualenv) or containers (e.g. LXC or Docker).
– Kevin
Sep 13 '16 at 19:38




1




1




In reference to soulsource’s warning at the top see PEP 394 which standardises naming conventions for coexisting Python executables and on which Python programmers and package maintainers do (and should) rely.
– David Foerster
Jun 25 at 11:26






In reference to soulsource’s warning at the top see PEP 394 which standardises naming conventions for coexisting Python executables and on which Python programmers and package maintainers do (and should) rely.
– David Foerster
Jun 25 at 11:26






1




1




@wjandrea, yes even in a virtual environment, python should be kept as meaning python2. I meant my comment as a way to have an application specific Python version instead of trying to work around the system's Python.
– Kevin
Dec 5 at 18:57




@wjandrea, yes even in a virtual environment, python should be kept as meaning python2. I meant my comment as a way to have an application specific Python version instead of trying to work around the system's Python.
– Kevin
Dec 5 at 18:57










9 Answers
9






active

oldest

votes

















up vote
286
down vote



accepted










A simple safe way would be to use an alias. Place this into ~/.bashrc or ~/.bash_aliases file:





alias python=python3


After adding the above in the file, run source ~/.bashrc or source ~/.bash_aliases.



For example:



$ python --version
Python 2.7.6
$ python3 --version
Python 3.4.3
$ alias python=python3
$ python --version
Python 3.4.3


To circumvent the alias use the command built-in command:



$ command python --version
Python 2.7.6


Another way to circumvent the alias is to use before the command.



$ python --version 
Python 2.7.6


To disable the alias in the current shell use the unalias built-in command:



$ unalias python
$ python --version
Python 2.7.6





share|improve this answer



















  • 1




    so no "upgrade" option..??
    – Giri
    Jul 17 '13 at 8:14










  • @Giri You said that you have python3. What for an upgrade?
    – Radu Rădeanu
    Jul 17 '13 at 8:16






  • 4




    actually i want to wipe-out 2.7 and replace it with 3.3. Seems like its a bad idea for now..
    – Giri
    Jul 17 '13 at 8:26






  • 29




    +1 there is no reason to purge 2.7 in order to be able to work with 3.3. As lots of software still depends on 2.7; just keep it lingering around.
    – don.joey
    Jul 17 '13 at 9:39






  • 4




    @begueradj An alias is totally different from a symbolic link.
    – Radu Rădeanu
    Jun 3 '14 at 7:41




















up vote
68
down vote













[June 2016] The recommended place for information on the transition is official Ubuntu Python page.





From the Ubuntu wiki:




For both Ubuntu and Debian, we have ongoing project goals to make Python 3 the default, preferred Python version in the distros.



What this does not mean:




  • /usr/bin/python will point to Python 3. No, this is not going to happen (unless PEP 394 advocates otherwise, which is doubtful for the foreseeable future). /usr/bin/python and /usr/bin/python2 will point to Python 2.7 and /usr/bin/python3 will point to the latest supported Python 3 version.


  • Python 2 will be removed from the archive. No, this is not going to happen. We expect Python 2.7 to remain supported and available in Ubuntu for quite a long time, given that PEP 373 promises upstream bug fix maintenance support until 2020.





It is not recommended to change the symbolic link because of other package dependencies, but they "have ongoing project goals to make Python 3 the default, preferred Python version in the distros".





For CLI use, like @Radu Rădeanu, I would recommend putting an alias in the user's ~/.bashrc, .bash_aliases file (the different files, including ~/.bash_profile, are loaded at least once, are mostly for organizational purposes, but may vary by platform). Python virtual environments also work well.



Alias examples:



alias python=python3


or



alias python='/usr/bin/python3'


Scripts should still use something like #!/usr/bin/env python3 for cross-compatibility.



Using env is nice for mixed use with virtual environments.



Note (thanks to @wjandrea): aliases are part of the bash runtime, not the user environment. Therefore, they are not available to the shebang (#!). If you prefer the alias python=python3, then some program.py without a shebang could be executed by invoking the aliased interpreter like this python program.py. Aliasing may also be useful for systems with multiple version of python3 like 3.4 and 3.6 together.






share|improve this answer



















  • 1




    This seems to be out of date now: they planned to remove python2 in Xenial, but then didn't.
    – OrangeDog
    Jun 20 '16 at 11:30






  • 1




    @OrangeDog, thanks for the update. Yes, the wiki-page I cited is now flagged as out-of-date, as more progress has been made in the past two years for moving to only Python 3. The new page to follow this progression is the official Ubuntu Python page.
    – Kevin
    Jun 20 '16 at 13:27










  • The "latest" page is also out of date, regarding the plans for Xenial.
    – OrangeDog
    Jun 20 '16 at 13:42










  • I would not say it is "out of date" so much as "it has not been updated recently." It still seems to be the current location for keeping posts about this. However, in the comments here, I would appreciate any other recent sources anyone may find. Adding more sources to my answer, about why not to make the change to just python, is not really relevant until the conversion is complete. Even then, it may just become a non-issue.
    – Kevin
    Jun 20 '16 at 13:51






  • 1




    Aliases are internal to Bash, not part of the environment, so you will still need to use python3 in a shebang, not python.
    – wjandrea
    Sep 28 at 22:51


















up vote
11
down vote













Update: This is the wrong way, I have learned, since Python2 and Python3 are not interchangeable.



You can try the command line tool update-alternatives.



$ sudo update-alternatives --config python


If you get the error "no alternatives for python" then set up an alternative yourself with the following command:



$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10


Change the path /usr/bin/python3 to your desired python version accordingly.






share|improve this answer



















  • 11




    python2 and python3 are not alternatives. Do not use update-alternatives for this purpose.
    – jobin
    Jun 2 '14 at 18:37










  • Why aren't they? Can one of you please explain why update-alternatives is not suitable for python? Is it because of legacy.python.org/dev/peps/pep-0394 ?
    – Dmitry Grigoryev
    Feb 19 '16 at 14:28








  • 6




    alternatives are different implementations for the same functionalities. python2 and python3 do not provide the same functionalities.
    – Ely
    Dec 13 '16 at 19:01










  • You can do something like this if you manually installed (via ppa or whatever) other versions of python3. sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
    – David Baucum
    Aug 20 at 14:45




















up vote
3
down vote













Ubuntu, and the rest of the Linux distros for that matter, are still largely dependent on Python 2.7 for a number of applications and commands. If you change the default reference of "python" to Python 3.x, then a number of Python functions will start throwing assertion errors.



For example, on Ubuntu, 'pip' for one would no longer run correctly unless you directly edited the file and changed the shebang to reference '#!/usr/bin/env python2.7'. On RHEL (Red Hat Enterprise Linux) flavors such as Red Hat, Fedora and CentOS, the 'Yum' command is also dependent on Python 2.7.



My point here is that you would cause a significant amount of code to start throwing assertion errors just so you could type 'python' in the terminal to reference Python 3.x.



You're much better off with using the 'python3' command in the terminal and the shebang '#!/usr/bin/env python3' in your Python 3.x files.






share|improve this answer




























    up vote
    1
    down vote













    Do



    cd ~
    gedit .bash_aliases


    then write either



    alias python=python3


    or



    alias python='/usr/bin/python3'


    Save the file, close the terminal and open it again.
    Link






    share|improve this answer






























      up vote
      0
      down vote













      cat > /usr/local/bin/py
      #!/bin/dash
      python3 "$@"
      <CTRL-D>


      (provided you have write permission to /usr/local/bin)
      likewise



      cat > /usr/local/bin/pyi
      #!/bin/dash
      python3 -i "$@"
      <CTRL-D>


      then you only type py (and use py in #! lines) for your chosen python.






      share|improve this answer























      • Wouldn't it be simpler to use a symlink? sudo ln -s /usr/bin/python3 /usr/local/bin/py
        – wjandrea
        Dec 4 at 1:31


















      up vote
      -1
      down vote













      You can use update-alternatives to provide different versions of programs that may be needed at different times due to compatibility issues.



      This answer Is a good example for how to set things up for simultaneously maintaining different versions of gcc/g++, for example.



      just do the same with python2.7 and python 3.3






      share|improve this answer



















      • 2




        Beginning users may not be able to easily adapt the linked answer to a different situation. In addition to crediting the earlier answer, it would be good to lay out the steps needed for Python.
        – chaskes
        Oct 18 '13 at 14:47










      • Here is i found good step by step solution linuxconfig.org/…
        – woto
        Mar 12 '17 at 14:50










      • Python 2 and 3 aren't alternatives - even different minor versions aren't (e.g.). This method can easily break things.
        – wjandrea
        Nov 30 at 14:35












      • Also this is a duplicate of this answer
        – wjandrea
        Nov 30 at 14:44


















      up vote
      -1
      down vote













      You can symlink /usr/bin/python to python3 with



      sudo ln -s /usr/bin/python3 /usr/bin/python


      See the other answers for why you might not want to do this. Ubuntu 18.04 no longer comes with Python 2, so it shouldn't be too bad.






      share|improve this answer

















      • 1




        Regarding "Ubuntu 18.04 no longer comes with Python 2, so it shouldn't be too bad.", on Ubuntu (even versions that don't have Python 2 installed by default), an executable called python is assumed to be Python 2, so this could break some things.
        – wjandrea
        Nov 30 at 14:33












      • *python -> /usr/bin/python
        – wjandrea
        Nov 30 at 15:26




















      up vote
      -2
      down vote













      Just write these two commands



      $echo "alias python=python3" >> ~/.bashrc



      followed by



      $source ~/.bashrc



      and then test that it works



      $python --version






      share|improve this answer

















      • 2




        Duplicate of top answer
        – wjandrea
        Nov 30 at 14:41










      protected by heemayl Mar 25 '16 at 17:01



      Thank you for your interest in this question.
      Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



      Would you like to answer one of these unanswered questions instead?














      9 Answers
      9






      active

      oldest

      votes








      9 Answers
      9






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      286
      down vote



      accepted










      A simple safe way would be to use an alias. Place this into ~/.bashrc or ~/.bash_aliases file:





      alias python=python3


      After adding the above in the file, run source ~/.bashrc or source ~/.bash_aliases.



      For example:



      $ python --version
      Python 2.7.6
      $ python3 --version
      Python 3.4.3
      $ alias python=python3
      $ python --version
      Python 3.4.3


      To circumvent the alias use the command built-in command:



      $ command python --version
      Python 2.7.6


      Another way to circumvent the alias is to use before the command.



      $ python --version 
      Python 2.7.6


      To disable the alias in the current shell use the unalias built-in command:



      $ unalias python
      $ python --version
      Python 2.7.6





      share|improve this answer



















      • 1




        so no "upgrade" option..??
        – Giri
        Jul 17 '13 at 8:14










      • @Giri You said that you have python3. What for an upgrade?
        – Radu Rădeanu
        Jul 17 '13 at 8:16






      • 4




        actually i want to wipe-out 2.7 and replace it with 3.3. Seems like its a bad idea for now..
        – Giri
        Jul 17 '13 at 8:26






      • 29




        +1 there is no reason to purge 2.7 in order to be able to work with 3.3. As lots of software still depends on 2.7; just keep it lingering around.
        – don.joey
        Jul 17 '13 at 9:39






      • 4




        @begueradj An alias is totally different from a symbolic link.
        – Radu Rădeanu
        Jun 3 '14 at 7:41

















      up vote
      286
      down vote



      accepted










      A simple safe way would be to use an alias. Place this into ~/.bashrc or ~/.bash_aliases file:





      alias python=python3


      After adding the above in the file, run source ~/.bashrc or source ~/.bash_aliases.



      For example:



      $ python --version
      Python 2.7.6
      $ python3 --version
      Python 3.4.3
      $ alias python=python3
      $ python --version
      Python 3.4.3


      To circumvent the alias use the command built-in command:



      $ command python --version
      Python 2.7.6


      Another way to circumvent the alias is to use before the command.



      $ python --version 
      Python 2.7.6


      To disable the alias in the current shell use the unalias built-in command:



      $ unalias python
      $ python --version
      Python 2.7.6





      share|improve this answer



















      • 1




        so no "upgrade" option..??
        – Giri
        Jul 17 '13 at 8:14










      • @Giri You said that you have python3. What for an upgrade?
        – Radu Rădeanu
        Jul 17 '13 at 8:16






      • 4




        actually i want to wipe-out 2.7 and replace it with 3.3. Seems like its a bad idea for now..
        – Giri
        Jul 17 '13 at 8:26






      • 29




        +1 there is no reason to purge 2.7 in order to be able to work with 3.3. As lots of software still depends on 2.7; just keep it lingering around.
        – don.joey
        Jul 17 '13 at 9:39






      • 4




        @begueradj An alias is totally different from a symbolic link.
        – Radu Rădeanu
        Jun 3 '14 at 7:41















      up vote
      286
      down vote



      accepted







      up vote
      286
      down vote



      accepted






      A simple safe way would be to use an alias. Place this into ~/.bashrc or ~/.bash_aliases file:





      alias python=python3


      After adding the above in the file, run source ~/.bashrc or source ~/.bash_aliases.



      For example:



      $ python --version
      Python 2.7.6
      $ python3 --version
      Python 3.4.3
      $ alias python=python3
      $ python --version
      Python 3.4.3


      To circumvent the alias use the command built-in command:



      $ command python --version
      Python 2.7.6


      Another way to circumvent the alias is to use before the command.



      $ python --version 
      Python 2.7.6


      To disable the alias in the current shell use the unalias built-in command:



      $ unalias python
      $ python --version
      Python 2.7.6





      share|improve this answer














      A simple safe way would be to use an alias. Place this into ~/.bashrc or ~/.bash_aliases file:





      alias python=python3


      After adding the above in the file, run source ~/.bashrc or source ~/.bash_aliases.



      For example:



      $ python --version
      Python 2.7.6
      $ python3 --version
      Python 3.4.3
      $ alias python=python3
      $ python --version
      Python 3.4.3


      To circumvent the alias use the command built-in command:



      $ command python --version
      Python 2.7.6


      Another way to circumvent the alias is to use before the command.



      $ python --version 
      Python 2.7.6


      To disable the alias in the current shell use the unalias built-in command:



      $ unalias python
      $ python --version
      Python 2.7.6






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 30 at 14:43









      wjandrea

      8,05142258




      8,05142258










      answered Jul 17 '13 at 8:13









      Radu Rădeanu

      115k34245321




      115k34245321








      • 1




        so no "upgrade" option..??
        – Giri
        Jul 17 '13 at 8:14










      • @Giri You said that you have python3. What for an upgrade?
        – Radu Rădeanu
        Jul 17 '13 at 8:16






      • 4




        actually i want to wipe-out 2.7 and replace it with 3.3. Seems like its a bad idea for now..
        – Giri
        Jul 17 '13 at 8:26






      • 29




        +1 there is no reason to purge 2.7 in order to be able to work with 3.3. As lots of software still depends on 2.7; just keep it lingering around.
        – don.joey
        Jul 17 '13 at 9:39






      • 4




        @begueradj An alias is totally different from a symbolic link.
        – Radu Rădeanu
        Jun 3 '14 at 7:41
















      • 1




        so no "upgrade" option..??
        – Giri
        Jul 17 '13 at 8:14










      • @Giri You said that you have python3. What for an upgrade?
        – Radu Rădeanu
        Jul 17 '13 at 8:16






      • 4




        actually i want to wipe-out 2.7 and replace it with 3.3. Seems like its a bad idea for now..
        – Giri
        Jul 17 '13 at 8:26






      • 29




        +1 there is no reason to purge 2.7 in order to be able to work with 3.3. As lots of software still depends on 2.7; just keep it lingering around.
        – don.joey
        Jul 17 '13 at 9:39






      • 4




        @begueradj An alias is totally different from a symbolic link.
        – Radu Rădeanu
        Jun 3 '14 at 7:41










      1




      1




      so no "upgrade" option..??
      – Giri
      Jul 17 '13 at 8:14




      so no "upgrade" option..??
      – Giri
      Jul 17 '13 at 8:14












      @Giri You said that you have python3. What for an upgrade?
      – Radu Rădeanu
      Jul 17 '13 at 8:16




      @Giri You said that you have python3. What for an upgrade?
      – Radu Rădeanu
      Jul 17 '13 at 8:16




      4




      4




      actually i want to wipe-out 2.7 and replace it with 3.3. Seems like its a bad idea for now..
      – Giri
      Jul 17 '13 at 8:26




      actually i want to wipe-out 2.7 and replace it with 3.3. Seems like its a bad idea for now..
      – Giri
      Jul 17 '13 at 8:26




      29




      29




      +1 there is no reason to purge 2.7 in order to be able to work with 3.3. As lots of software still depends on 2.7; just keep it lingering around.
      – don.joey
      Jul 17 '13 at 9:39




      +1 there is no reason to purge 2.7 in order to be able to work with 3.3. As lots of software still depends on 2.7; just keep it lingering around.
      – don.joey
      Jul 17 '13 at 9:39




      4




      4




      @begueradj An alias is totally different from a symbolic link.
      – Radu Rădeanu
      Jun 3 '14 at 7:41






      @begueradj An alias is totally different from a symbolic link.
      – Radu Rădeanu
      Jun 3 '14 at 7:41














      up vote
      68
      down vote













      [June 2016] The recommended place for information on the transition is official Ubuntu Python page.





      From the Ubuntu wiki:




      For both Ubuntu and Debian, we have ongoing project goals to make Python 3 the default, preferred Python version in the distros.



      What this does not mean:




      • /usr/bin/python will point to Python 3. No, this is not going to happen (unless PEP 394 advocates otherwise, which is doubtful for the foreseeable future). /usr/bin/python and /usr/bin/python2 will point to Python 2.7 and /usr/bin/python3 will point to the latest supported Python 3 version.


      • Python 2 will be removed from the archive. No, this is not going to happen. We expect Python 2.7 to remain supported and available in Ubuntu for quite a long time, given that PEP 373 promises upstream bug fix maintenance support until 2020.





      It is not recommended to change the symbolic link because of other package dependencies, but they "have ongoing project goals to make Python 3 the default, preferred Python version in the distros".





      For CLI use, like @Radu Rădeanu, I would recommend putting an alias in the user's ~/.bashrc, .bash_aliases file (the different files, including ~/.bash_profile, are loaded at least once, are mostly for organizational purposes, but may vary by platform). Python virtual environments also work well.



      Alias examples:



      alias python=python3


      or



      alias python='/usr/bin/python3'


      Scripts should still use something like #!/usr/bin/env python3 for cross-compatibility.



      Using env is nice for mixed use with virtual environments.



      Note (thanks to @wjandrea): aliases are part of the bash runtime, not the user environment. Therefore, they are not available to the shebang (#!). If you prefer the alias python=python3, then some program.py without a shebang could be executed by invoking the aliased interpreter like this python program.py. Aliasing may also be useful for systems with multiple version of python3 like 3.4 and 3.6 together.






      share|improve this answer



















      • 1




        This seems to be out of date now: they planned to remove python2 in Xenial, but then didn't.
        – OrangeDog
        Jun 20 '16 at 11:30






      • 1




        @OrangeDog, thanks for the update. Yes, the wiki-page I cited is now flagged as out-of-date, as more progress has been made in the past two years for moving to only Python 3. The new page to follow this progression is the official Ubuntu Python page.
        – Kevin
        Jun 20 '16 at 13:27










      • The "latest" page is also out of date, regarding the plans for Xenial.
        – OrangeDog
        Jun 20 '16 at 13:42










      • I would not say it is "out of date" so much as "it has not been updated recently." It still seems to be the current location for keeping posts about this. However, in the comments here, I would appreciate any other recent sources anyone may find. Adding more sources to my answer, about why not to make the change to just python, is not really relevant until the conversion is complete. Even then, it may just become a non-issue.
        – Kevin
        Jun 20 '16 at 13:51






      • 1




        Aliases are internal to Bash, not part of the environment, so you will still need to use python3 in a shebang, not python.
        – wjandrea
        Sep 28 at 22:51















      up vote
      68
      down vote













      [June 2016] The recommended place for information on the transition is official Ubuntu Python page.





      From the Ubuntu wiki:




      For both Ubuntu and Debian, we have ongoing project goals to make Python 3 the default, preferred Python version in the distros.



      What this does not mean:




      • /usr/bin/python will point to Python 3. No, this is not going to happen (unless PEP 394 advocates otherwise, which is doubtful for the foreseeable future). /usr/bin/python and /usr/bin/python2 will point to Python 2.7 and /usr/bin/python3 will point to the latest supported Python 3 version.


      • Python 2 will be removed from the archive. No, this is not going to happen. We expect Python 2.7 to remain supported and available in Ubuntu for quite a long time, given that PEP 373 promises upstream bug fix maintenance support until 2020.





      It is not recommended to change the symbolic link because of other package dependencies, but they "have ongoing project goals to make Python 3 the default, preferred Python version in the distros".





      For CLI use, like @Radu Rădeanu, I would recommend putting an alias in the user's ~/.bashrc, .bash_aliases file (the different files, including ~/.bash_profile, are loaded at least once, are mostly for organizational purposes, but may vary by platform). Python virtual environments also work well.



      Alias examples:



      alias python=python3


      or



      alias python='/usr/bin/python3'


      Scripts should still use something like #!/usr/bin/env python3 for cross-compatibility.



      Using env is nice for mixed use with virtual environments.



      Note (thanks to @wjandrea): aliases are part of the bash runtime, not the user environment. Therefore, they are not available to the shebang (#!). If you prefer the alias python=python3, then some program.py without a shebang could be executed by invoking the aliased interpreter like this python program.py. Aliasing may also be useful for systems with multiple version of python3 like 3.4 and 3.6 together.






      share|improve this answer



















      • 1




        This seems to be out of date now: they planned to remove python2 in Xenial, but then didn't.
        – OrangeDog
        Jun 20 '16 at 11:30






      • 1




        @OrangeDog, thanks for the update. Yes, the wiki-page I cited is now flagged as out-of-date, as more progress has been made in the past two years for moving to only Python 3. The new page to follow this progression is the official Ubuntu Python page.
        – Kevin
        Jun 20 '16 at 13:27










      • The "latest" page is also out of date, regarding the plans for Xenial.
        – OrangeDog
        Jun 20 '16 at 13:42










      • I would not say it is "out of date" so much as "it has not been updated recently." It still seems to be the current location for keeping posts about this. However, in the comments here, I would appreciate any other recent sources anyone may find. Adding more sources to my answer, about why not to make the change to just python, is not really relevant until the conversion is complete. Even then, it may just become a non-issue.
        – Kevin
        Jun 20 '16 at 13:51






      • 1




        Aliases are internal to Bash, not part of the environment, so you will still need to use python3 in a shebang, not python.
        – wjandrea
        Sep 28 at 22:51













      up vote
      68
      down vote










      up vote
      68
      down vote









      [June 2016] The recommended place for information on the transition is official Ubuntu Python page.





      From the Ubuntu wiki:




      For both Ubuntu and Debian, we have ongoing project goals to make Python 3 the default, preferred Python version in the distros.



      What this does not mean:




      • /usr/bin/python will point to Python 3. No, this is not going to happen (unless PEP 394 advocates otherwise, which is doubtful for the foreseeable future). /usr/bin/python and /usr/bin/python2 will point to Python 2.7 and /usr/bin/python3 will point to the latest supported Python 3 version.


      • Python 2 will be removed from the archive. No, this is not going to happen. We expect Python 2.7 to remain supported and available in Ubuntu for quite a long time, given that PEP 373 promises upstream bug fix maintenance support until 2020.





      It is not recommended to change the symbolic link because of other package dependencies, but they "have ongoing project goals to make Python 3 the default, preferred Python version in the distros".





      For CLI use, like @Radu Rădeanu, I would recommend putting an alias in the user's ~/.bashrc, .bash_aliases file (the different files, including ~/.bash_profile, are loaded at least once, are mostly for organizational purposes, but may vary by platform). Python virtual environments also work well.



      Alias examples:



      alias python=python3


      or



      alias python='/usr/bin/python3'


      Scripts should still use something like #!/usr/bin/env python3 for cross-compatibility.



      Using env is nice for mixed use with virtual environments.



      Note (thanks to @wjandrea): aliases are part of the bash runtime, not the user environment. Therefore, they are not available to the shebang (#!). If you prefer the alias python=python3, then some program.py without a shebang could be executed by invoking the aliased interpreter like this python program.py. Aliasing may also be useful for systems with multiple version of python3 like 3.4 and 3.6 together.






      share|improve this answer














      [June 2016] The recommended place for information on the transition is official Ubuntu Python page.





      From the Ubuntu wiki:




      For both Ubuntu and Debian, we have ongoing project goals to make Python 3 the default, preferred Python version in the distros.



      What this does not mean:




      • /usr/bin/python will point to Python 3. No, this is not going to happen (unless PEP 394 advocates otherwise, which is doubtful for the foreseeable future). /usr/bin/python and /usr/bin/python2 will point to Python 2.7 and /usr/bin/python3 will point to the latest supported Python 3 version.


      • Python 2 will be removed from the archive. No, this is not going to happen. We expect Python 2.7 to remain supported and available in Ubuntu for quite a long time, given that PEP 373 promises upstream bug fix maintenance support until 2020.





      It is not recommended to change the symbolic link because of other package dependencies, but they "have ongoing project goals to make Python 3 the default, preferred Python version in the distros".





      For CLI use, like @Radu Rădeanu, I would recommend putting an alias in the user's ~/.bashrc, .bash_aliases file (the different files, including ~/.bash_profile, are loaded at least once, are mostly for organizational purposes, but may vary by platform). Python virtual environments also work well.



      Alias examples:



      alias python=python3


      or



      alias python='/usr/bin/python3'


      Scripts should still use something like #!/usr/bin/env python3 for cross-compatibility.



      Using env is nice for mixed use with virtual environments.



      Note (thanks to @wjandrea): aliases are part of the bash runtime, not the user environment. Therefore, they are not available to the shebang (#!). If you prefer the alias python=python3, then some program.py without a shebang could be executed by invoking the aliased interpreter like this python program.py. Aliasing may also be useful for systems with multiple version of python3 like 3.4 and 3.6 together.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Oct 1 at 2:20

























      answered Jun 2 '14 at 16:31









      Kevin

      893711




      893711








      • 1




        This seems to be out of date now: they planned to remove python2 in Xenial, but then didn't.
        – OrangeDog
        Jun 20 '16 at 11:30






      • 1




        @OrangeDog, thanks for the update. Yes, the wiki-page I cited is now flagged as out-of-date, as more progress has been made in the past two years for moving to only Python 3. The new page to follow this progression is the official Ubuntu Python page.
        – Kevin
        Jun 20 '16 at 13:27










      • The "latest" page is also out of date, regarding the plans for Xenial.
        – OrangeDog
        Jun 20 '16 at 13:42










      • I would not say it is "out of date" so much as "it has not been updated recently." It still seems to be the current location for keeping posts about this. However, in the comments here, I would appreciate any other recent sources anyone may find. Adding more sources to my answer, about why not to make the change to just python, is not really relevant until the conversion is complete. Even then, it may just become a non-issue.
        – Kevin
        Jun 20 '16 at 13:51






      • 1




        Aliases are internal to Bash, not part of the environment, so you will still need to use python3 in a shebang, not python.
        – wjandrea
        Sep 28 at 22:51














      • 1




        This seems to be out of date now: they planned to remove python2 in Xenial, but then didn't.
        – OrangeDog
        Jun 20 '16 at 11:30






      • 1




        @OrangeDog, thanks for the update. Yes, the wiki-page I cited is now flagged as out-of-date, as more progress has been made in the past two years for moving to only Python 3. The new page to follow this progression is the official Ubuntu Python page.
        – Kevin
        Jun 20 '16 at 13:27










      • The "latest" page is also out of date, regarding the plans for Xenial.
        – OrangeDog
        Jun 20 '16 at 13:42










      • I would not say it is "out of date" so much as "it has not been updated recently." It still seems to be the current location for keeping posts about this. However, in the comments here, I would appreciate any other recent sources anyone may find. Adding more sources to my answer, about why not to make the change to just python, is not really relevant until the conversion is complete. Even then, it may just become a non-issue.
        – Kevin
        Jun 20 '16 at 13:51






      • 1




        Aliases are internal to Bash, not part of the environment, so you will still need to use python3 in a shebang, not python.
        – wjandrea
        Sep 28 at 22:51








      1




      1




      This seems to be out of date now: they planned to remove python2 in Xenial, but then didn't.
      – OrangeDog
      Jun 20 '16 at 11:30




      This seems to be out of date now: they planned to remove python2 in Xenial, but then didn't.
      – OrangeDog
      Jun 20 '16 at 11:30




      1




      1




      @OrangeDog, thanks for the update. Yes, the wiki-page I cited is now flagged as out-of-date, as more progress has been made in the past two years for moving to only Python 3. The new page to follow this progression is the official Ubuntu Python page.
      – Kevin
      Jun 20 '16 at 13:27




      @OrangeDog, thanks for the update. Yes, the wiki-page I cited is now flagged as out-of-date, as more progress has been made in the past two years for moving to only Python 3. The new page to follow this progression is the official Ubuntu Python page.
      – Kevin
      Jun 20 '16 at 13:27












      The "latest" page is also out of date, regarding the plans for Xenial.
      – OrangeDog
      Jun 20 '16 at 13:42




      The "latest" page is also out of date, regarding the plans for Xenial.
      – OrangeDog
      Jun 20 '16 at 13:42












      I would not say it is "out of date" so much as "it has not been updated recently." It still seems to be the current location for keeping posts about this. However, in the comments here, I would appreciate any other recent sources anyone may find. Adding more sources to my answer, about why not to make the change to just python, is not really relevant until the conversion is complete. Even then, it may just become a non-issue.
      – Kevin
      Jun 20 '16 at 13:51




      I would not say it is "out of date" so much as "it has not been updated recently." It still seems to be the current location for keeping posts about this. However, in the comments here, I would appreciate any other recent sources anyone may find. Adding more sources to my answer, about why not to make the change to just python, is not really relevant until the conversion is complete. Even then, it may just become a non-issue.
      – Kevin
      Jun 20 '16 at 13:51




      1




      1




      Aliases are internal to Bash, not part of the environment, so you will still need to use python3 in a shebang, not python.
      – wjandrea
      Sep 28 at 22:51




      Aliases are internal to Bash, not part of the environment, so you will still need to use python3 in a shebang, not python.
      – wjandrea
      Sep 28 at 22:51










      up vote
      11
      down vote













      Update: This is the wrong way, I have learned, since Python2 and Python3 are not interchangeable.



      You can try the command line tool update-alternatives.



      $ sudo update-alternatives --config python


      If you get the error "no alternatives for python" then set up an alternative yourself with the following command:



      $ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10


      Change the path /usr/bin/python3 to your desired python version accordingly.






      share|improve this answer



















      • 11




        python2 and python3 are not alternatives. Do not use update-alternatives for this purpose.
        – jobin
        Jun 2 '14 at 18:37










      • Why aren't they? Can one of you please explain why update-alternatives is not suitable for python? Is it because of legacy.python.org/dev/peps/pep-0394 ?
        – Dmitry Grigoryev
        Feb 19 '16 at 14:28








      • 6




        alternatives are different implementations for the same functionalities. python2 and python3 do not provide the same functionalities.
        – Ely
        Dec 13 '16 at 19:01










      • You can do something like this if you manually installed (via ppa or whatever) other versions of python3. sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
        – David Baucum
        Aug 20 at 14:45

















      up vote
      11
      down vote













      Update: This is the wrong way, I have learned, since Python2 and Python3 are not interchangeable.



      You can try the command line tool update-alternatives.



      $ sudo update-alternatives --config python


      If you get the error "no alternatives for python" then set up an alternative yourself with the following command:



      $ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10


      Change the path /usr/bin/python3 to your desired python version accordingly.






      share|improve this answer



















      • 11




        python2 and python3 are not alternatives. Do not use update-alternatives for this purpose.
        – jobin
        Jun 2 '14 at 18:37










      • Why aren't they? Can one of you please explain why update-alternatives is not suitable for python? Is it because of legacy.python.org/dev/peps/pep-0394 ?
        – Dmitry Grigoryev
        Feb 19 '16 at 14:28








      • 6




        alternatives are different implementations for the same functionalities. python2 and python3 do not provide the same functionalities.
        – Ely
        Dec 13 '16 at 19:01










      • You can do something like this if you manually installed (via ppa or whatever) other versions of python3. sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
        – David Baucum
        Aug 20 at 14:45















      up vote
      11
      down vote










      up vote
      11
      down vote









      Update: This is the wrong way, I have learned, since Python2 and Python3 are not interchangeable.



      You can try the command line tool update-alternatives.



      $ sudo update-alternatives --config python


      If you get the error "no alternatives for python" then set up an alternative yourself with the following command:



      $ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10


      Change the path /usr/bin/python3 to your desired python version accordingly.






      share|improve this answer














      Update: This is the wrong way, I have learned, since Python2 and Python3 are not interchangeable.



      You can try the command line tool update-alternatives.



      $ sudo update-alternatives --config python


      If you get the error "no alternatives for python" then set up an alternative yourself with the following command:



      $ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10


      Change the path /usr/bin/python3 to your desired python version accordingly.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Apr 5 '17 at 16:40









      wjandrea

      8,05142258




      8,05142258










      answered May 4 '14 at 14:03









      webwurst

      1,2501211




      1,2501211








      • 11




        python2 and python3 are not alternatives. Do not use update-alternatives for this purpose.
        – jobin
        Jun 2 '14 at 18:37










      • Why aren't they? Can one of you please explain why update-alternatives is not suitable for python? Is it because of legacy.python.org/dev/peps/pep-0394 ?
        – Dmitry Grigoryev
        Feb 19 '16 at 14:28








      • 6




        alternatives are different implementations for the same functionalities. python2 and python3 do not provide the same functionalities.
        – Ely
        Dec 13 '16 at 19:01










      • You can do something like this if you manually installed (via ppa or whatever) other versions of python3. sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
        – David Baucum
        Aug 20 at 14:45
















      • 11




        python2 and python3 are not alternatives. Do not use update-alternatives for this purpose.
        – jobin
        Jun 2 '14 at 18:37










      • Why aren't they? Can one of you please explain why update-alternatives is not suitable for python? Is it because of legacy.python.org/dev/peps/pep-0394 ?
        – Dmitry Grigoryev
        Feb 19 '16 at 14:28








      • 6




        alternatives are different implementations for the same functionalities. python2 and python3 do not provide the same functionalities.
        – Ely
        Dec 13 '16 at 19:01










      • You can do something like this if you manually installed (via ppa or whatever) other versions of python3. sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
        – David Baucum
        Aug 20 at 14:45










      11




      11




      python2 and python3 are not alternatives. Do not use update-alternatives for this purpose.
      – jobin
      Jun 2 '14 at 18:37




      python2 and python3 are not alternatives. Do not use update-alternatives for this purpose.
      – jobin
      Jun 2 '14 at 18:37












      Why aren't they? Can one of you please explain why update-alternatives is not suitable for python? Is it because of legacy.python.org/dev/peps/pep-0394 ?
      – Dmitry Grigoryev
      Feb 19 '16 at 14:28






      Why aren't they? Can one of you please explain why update-alternatives is not suitable for python? Is it because of legacy.python.org/dev/peps/pep-0394 ?
      – Dmitry Grigoryev
      Feb 19 '16 at 14:28






      6




      6




      alternatives are different implementations for the same functionalities. python2 and python3 do not provide the same functionalities.
      – Ely
      Dec 13 '16 at 19:01




      alternatives are different implementations for the same functionalities. python2 and python3 do not provide the same functionalities.
      – Ely
      Dec 13 '16 at 19:01












      You can do something like this if you manually installed (via ppa or whatever) other versions of python3. sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
      – David Baucum
      Aug 20 at 14:45






      You can do something like this if you manually installed (via ppa or whatever) other versions of python3. sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
      – David Baucum
      Aug 20 at 14:45












      up vote
      3
      down vote













      Ubuntu, and the rest of the Linux distros for that matter, are still largely dependent on Python 2.7 for a number of applications and commands. If you change the default reference of "python" to Python 3.x, then a number of Python functions will start throwing assertion errors.



      For example, on Ubuntu, 'pip' for one would no longer run correctly unless you directly edited the file and changed the shebang to reference '#!/usr/bin/env python2.7'. On RHEL (Red Hat Enterprise Linux) flavors such as Red Hat, Fedora and CentOS, the 'Yum' command is also dependent on Python 2.7.



      My point here is that you would cause a significant amount of code to start throwing assertion errors just so you could type 'python' in the terminal to reference Python 3.x.



      You're much better off with using the 'python3' command in the terminal and the shebang '#!/usr/bin/env python3' in your Python 3.x files.






      share|improve this answer

























        up vote
        3
        down vote













        Ubuntu, and the rest of the Linux distros for that matter, are still largely dependent on Python 2.7 for a number of applications and commands. If you change the default reference of "python" to Python 3.x, then a number of Python functions will start throwing assertion errors.



        For example, on Ubuntu, 'pip' for one would no longer run correctly unless you directly edited the file and changed the shebang to reference '#!/usr/bin/env python2.7'. On RHEL (Red Hat Enterprise Linux) flavors such as Red Hat, Fedora and CentOS, the 'Yum' command is also dependent on Python 2.7.



        My point here is that you would cause a significant amount of code to start throwing assertion errors just so you could type 'python' in the terminal to reference Python 3.x.



        You're much better off with using the 'python3' command in the terminal and the shebang '#!/usr/bin/env python3' in your Python 3.x files.






        share|improve this answer























          up vote
          3
          down vote










          up vote
          3
          down vote









          Ubuntu, and the rest of the Linux distros for that matter, are still largely dependent on Python 2.7 for a number of applications and commands. If you change the default reference of "python" to Python 3.x, then a number of Python functions will start throwing assertion errors.



          For example, on Ubuntu, 'pip' for one would no longer run correctly unless you directly edited the file and changed the shebang to reference '#!/usr/bin/env python2.7'. On RHEL (Red Hat Enterprise Linux) flavors such as Red Hat, Fedora and CentOS, the 'Yum' command is also dependent on Python 2.7.



          My point here is that you would cause a significant amount of code to start throwing assertion errors just so you could type 'python' in the terminal to reference Python 3.x.



          You're much better off with using the 'python3' command in the terminal and the shebang '#!/usr/bin/env python3' in your Python 3.x files.






          share|improve this answer












          Ubuntu, and the rest of the Linux distros for that matter, are still largely dependent on Python 2.7 for a number of applications and commands. If you change the default reference of "python" to Python 3.x, then a number of Python functions will start throwing assertion errors.



          For example, on Ubuntu, 'pip' for one would no longer run correctly unless you directly edited the file and changed the shebang to reference '#!/usr/bin/env python2.7'. On RHEL (Red Hat Enterprise Linux) flavors such as Red Hat, Fedora and CentOS, the 'Yum' command is also dependent on Python 2.7.



          My point here is that you would cause a significant amount of code to start throwing assertion errors just so you could type 'python' in the terminal to reference Python 3.x.



          You're much better off with using the 'python3' command in the terminal and the shebang '#!/usr/bin/env python3' in your Python 3.x files.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 25 '16 at 15:43









          Moony

          312




          312






















              up vote
              1
              down vote













              Do



              cd ~
              gedit .bash_aliases


              then write either



              alias python=python3


              or



              alias python='/usr/bin/python3'


              Save the file, close the terminal and open it again.
              Link






              share|improve this answer



























                up vote
                1
                down vote













                Do



                cd ~
                gedit .bash_aliases


                then write either



                alias python=python3


                or



                alias python='/usr/bin/python3'


                Save the file, close the terminal and open it again.
                Link






                share|improve this answer

























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  Do



                  cd ~
                  gedit .bash_aliases


                  then write either



                  alias python=python3


                  or



                  alias python='/usr/bin/python3'


                  Save the file, close the terminal and open it again.
                  Link






                  share|improve this answer














                  Do



                  cd ~
                  gedit .bash_aliases


                  then write either



                  alias python=python3


                  or



                  alias python='/usr/bin/python3'


                  Save the file, close the terminal and open it again.
                  Link







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Dec 1 at 5:56

























                  answered Sep 15 '17 at 18:36









                  Breeze

                  507621




                  507621






















                      up vote
                      0
                      down vote













                      cat > /usr/local/bin/py
                      #!/bin/dash
                      python3 "$@"
                      <CTRL-D>


                      (provided you have write permission to /usr/local/bin)
                      likewise



                      cat > /usr/local/bin/pyi
                      #!/bin/dash
                      python3 -i "$@"
                      <CTRL-D>


                      then you only type py (and use py in #! lines) for your chosen python.






                      share|improve this answer























                      • Wouldn't it be simpler to use a symlink? sudo ln -s /usr/bin/python3 /usr/local/bin/py
                        – wjandrea
                        Dec 4 at 1:31















                      up vote
                      0
                      down vote













                      cat > /usr/local/bin/py
                      #!/bin/dash
                      python3 "$@"
                      <CTRL-D>


                      (provided you have write permission to /usr/local/bin)
                      likewise



                      cat > /usr/local/bin/pyi
                      #!/bin/dash
                      python3 -i "$@"
                      <CTRL-D>


                      then you only type py (and use py in #! lines) for your chosen python.






                      share|improve this answer























                      • Wouldn't it be simpler to use a symlink? sudo ln -s /usr/bin/python3 /usr/local/bin/py
                        – wjandrea
                        Dec 4 at 1:31













                      up vote
                      0
                      down vote










                      up vote
                      0
                      down vote









                      cat > /usr/local/bin/py
                      #!/bin/dash
                      python3 "$@"
                      <CTRL-D>


                      (provided you have write permission to /usr/local/bin)
                      likewise



                      cat > /usr/local/bin/pyi
                      #!/bin/dash
                      python3 -i "$@"
                      <CTRL-D>


                      then you only type py (and use py in #! lines) for your chosen python.






                      share|improve this answer














                      cat > /usr/local/bin/py
                      #!/bin/dash
                      python3 "$@"
                      <CTRL-D>


                      (provided you have write permission to /usr/local/bin)
                      likewise



                      cat > /usr/local/bin/pyi
                      #!/bin/dash
                      python3 -i "$@"
                      <CTRL-D>


                      then you only type py (and use py in #! lines) for your chosen python.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Dec 4 at 1:31









                      wjandrea

                      8,05142258




                      8,05142258










                      answered Jan 15 '16 at 22:57









                      John Allsup

                      1012




                      1012












                      • Wouldn't it be simpler to use a symlink? sudo ln -s /usr/bin/python3 /usr/local/bin/py
                        – wjandrea
                        Dec 4 at 1:31


















                      • Wouldn't it be simpler to use a symlink? sudo ln -s /usr/bin/python3 /usr/local/bin/py
                        – wjandrea
                        Dec 4 at 1:31
















                      Wouldn't it be simpler to use a symlink? sudo ln -s /usr/bin/python3 /usr/local/bin/py
                      – wjandrea
                      Dec 4 at 1:31




                      Wouldn't it be simpler to use a symlink? sudo ln -s /usr/bin/python3 /usr/local/bin/py
                      – wjandrea
                      Dec 4 at 1:31










                      up vote
                      -1
                      down vote













                      You can use update-alternatives to provide different versions of programs that may be needed at different times due to compatibility issues.



                      This answer Is a good example for how to set things up for simultaneously maintaining different versions of gcc/g++, for example.



                      just do the same with python2.7 and python 3.3






                      share|improve this answer



















                      • 2




                        Beginning users may not be able to easily adapt the linked answer to a different situation. In addition to crediting the earlier answer, it would be good to lay out the steps needed for Python.
                        – chaskes
                        Oct 18 '13 at 14:47










                      • Here is i found good step by step solution linuxconfig.org/…
                        – woto
                        Mar 12 '17 at 14:50










                      • Python 2 and 3 aren't alternatives - even different minor versions aren't (e.g.). This method can easily break things.
                        – wjandrea
                        Nov 30 at 14:35












                      • Also this is a duplicate of this answer
                        – wjandrea
                        Nov 30 at 14:44















                      up vote
                      -1
                      down vote













                      You can use update-alternatives to provide different versions of programs that may be needed at different times due to compatibility issues.



                      This answer Is a good example for how to set things up for simultaneously maintaining different versions of gcc/g++, for example.



                      just do the same with python2.7 and python 3.3






                      share|improve this answer



















                      • 2




                        Beginning users may not be able to easily adapt the linked answer to a different situation. In addition to crediting the earlier answer, it would be good to lay out the steps needed for Python.
                        – chaskes
                        Oct 18 '13 at 14:47










                      • Here is i found good step by step solution linuxconfig.org/…
                        – woto
                        Mar 12 '17 at 14:50










                      • Python 2 and 3 aren't alternatives - even different minor versions aren't (e.g.). This method can easily break things.
                        – wjandrea
                        Nov 30 at 14:35












                      • Also this is a duplicate of this answer
                        – wjandrea
                        Nov 30 at 14:44













                      up vote
                      -1
                      down vote










                      up vote
                      -1
                      down vote









                      You can use update-alternatives to provide different versions of programs that may be needed at different times due to compatibility issues.



                      This answer Is a good example for how to set things up for simultaneously maintaining different versions of gcc/g++, for example.



                      just do the same with python2.7 and python 3.3






                      share|improve this answer














                      You can use update-alternatives to provide different versions of programs that may be needed at different times due to compatibility issues.



                      This answer Is a good example for how to set things up for simultaneously maintaining different versions of gcc/g++, for example.



                      just do the same with python2.7 and python 3.3







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Apr 13 '17 at 12:25









                      Community

                      1




                      1










                      answered Oct 18 '13 at 13:19









                      dcanelhas

                      412




                      412








                      • 2




                        Beginning users may not be able to easily adapt the linked answer to a different situation. In addition to crediting the earlier answer, it would be good to lay out the steps needed for Python.
                        – chaskes
                        Oct 18 '13 at 14:47










                      • Here is i found good step by step solution linuxconfig.org/…
                        – woto
                        Mar 12 '17 at 14:50










                      • Python 2 and 3 aren't alternatives - even different minor versions aren't (e.g.). This method can easily break things.
                        – wjandrea
                        Nov 30 at 14:35












                      • Also this is a duplicate of this answer
                        – wjandrea
                        Nov 30 at 14:44














                      • 2




                        Beginning users may not be able to easily adapt the linked answer to a different situation. In addition to crediting the earlier answer, it would be good to lay out the steps needed for Python.
                        – chaskes
                        Oct 18 '13 at 14:47










                      • Here is i found good step by step solution linuxconfig.org/…
                        – woto
                        Mar 12 '17 at 14:50










                      • Python 2 and 3 aren't alternatives - even different minor versions aren't (e.g.). This method can easily break things.
                        – wjandrea
                        Nov 30 at 14:35












                      • Also this is a duplicate of this answer
                        – wjandrea
                        Nov 30 at 14:44








                      2




                      2




                      Beginning users may not be able to easily adapt the linked answer to a different situation. In addition to crediting the earlier answer, it would be good to lay out the steps needed for Python.
                      – chaskes
                      Oct 18 '13 at 14:47




                      Beginning users may not be able to easily adapt the linked answer to a different situation. In addition to crediting the earlier answer, it would be good to lay out the steps needed for Python.
                      – chaskes
                      Oct 18 '13 at 14:47












                      Here is i found good step by step solution linuxconfig.org/…
                      – woto
                      Mar 12 '17 at 14:50




                      Here is i found good step by step solution linuxconfig.org/…
                      – woto
                      Mar 12 '17 at 14:50












                      Python 2 and 3 aren't alternatives - even different minor versions aren't (e.g.). This method can easily break things.
                      – wjandrea
                      Nov 30 at 14:35






                      Python 2 and 3 aren't alternatives - even different minor versions aren't (e.g.). This method can easily break things.
                      – wjandrea
                      Nov 30 at 14:35














                      Also this is a duplicate of this answer
                      – wjandrea
                      Nov 30 at 14:44




                      Also this is a duplicate of this answer
                      – wjandrea
                      Nov 30 at 14:44










                      up vote
                      -1
                      down vote













                      You can symlink /usr/bin/python to python3 with



                      sudo ln -s /usr/bin/python3 /usr/bin/python


                      See the other answers for why you might not want to do this. Ubuntu 18.04 no longer comes with Python 2, so it shouldn't be too bad.






                      share|improve this answer

















                      • 1




                        Regarding "Ubuntu 18.04 no longer comes with Python 2, so it shouldn't be too bad.", on Ubuntu (even versions that don't have Python 2 installed by default), an executable called python is assumed to be Python 2, so this could break some things.
                        – wjandrea
                        Nov 30 at 14:33












                      • *python -> /usr/bin/python
                        – wjandrea
                        Nov 30 at 15:26

















                      up vote
                      -1
                      down vote













                      You can symlink /usr/bin/python to python3 with



                      sudo ln -s /usr/bin/python3 /usr/bin/python


                      See the other answers for why you might not want to do this. Ubuntu 18.04 no longer comes with Python 2, so it shouldn't be too bad.






                      share|improve this answer

















                      • 1




                        Regarding "Ubuntu 18.04 no longer comes with Python 2, so it shouldn't be too bad.", on Ubuntu (even versions that don't have Python 2 installed by default), an executable called python is assumed to be Python 2, so this could break some things.
                        – wjandrea
                        Nov 30 at 14:33












                      • *python -> /usr/bin/python
                        – wjandrea
                        Nov 30 at 15:26















                      up vote
                      -1
                      down vote










                      up vote
                      -1
                      down vote









                      You can symlink /usr/bin/python to python3 with



                      sudo ln -s /usr/bin/python3 /usr/bin/python


                      See the other answers for why you might not want to do this. Ubuntu 18.04 no longer comes with Python 2, so it shouldn't be too bad.






                      share|improve this answer












                      You can symlink /usr/bin/python to python3 with



                      sudo ln -s /usr/bin/python3 /usr/bin/python


                      See the other answers for why you might not want to do this. Ubuntu 18.04 no longer comes with Python 2, so it shouldn't be too bad.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered May 3 at 21:01









                      Boris

                      27937




                      27937








                      • 1




                        Regarding "Ubuntu 18.04 no longer comes with Python 2, so it shouldn't be too bad.", on Ubuntu (even versions that don't have Python 2 installed by default), an executable called python is assumed to be Python 2, so this could break some things.
                        – wjandrea
                        Nov 30 at 14:33












                      • *python -> /usr/bin/python
                        – wjandrea
                        Nov 30 at 15:26
















                      • 1




                        Regarding "Ubuntu 18.04 no longer comes with Python 2, so it shouldn't be too bad.", on Ubuntu (even versions that don't have Python 2 installed by default), an executable called python is assumed to be Python 2, so this could break some things.
                        – wjandrea
                        Nov 30 at 14:33












                      • *python -> /usr/bin/python
                        – wjandrea
                        Nov 30 at 15:26










                      1




                      1




                      Regarding "Ubuntu 18.04 no longer comes with Python 2, so it shouldn't be too bad.", on Ubuntu (even versions that don't have Python 2 installed by default), an executable called python is assumed to be Python 2, so this could break some things.
                      – wjandrea
                      Nov 30 at 14:33






                      Regarding "Ubuntu 18.04 no longer comes with Python 2, so it shouldn't be too bad.", on Ubuntu (even versions that don't have Python 2 installed by default), an executable called python is assumed to be Python 2, so this could break some things.
                      – wjandrea
                      Nov 30 at 14:33














                      *python -> /usr/bin/python
                      – wjandrea
                      Nov 30 at 15:26






                      *python -> /usr/bin/python
                      – wjandrea
                      Nov 30 at 15:26












                      up vote
                      -2
                      down vote













                      Just write these two commands



                      $echo "alias python=python3" >> ~/.bashrc



                      followed by



                      $source ~/.bashrc



                      and then test that it works



                      $python --version






                      share|improve this answer

















                      • 2




                        Duplicate of top answer
                        – wjandrea
                        Nov 30 at 14:41















                      up vote
                      -2
                      down vote













                      Just write these two commands



                      $echo "alias python=python3" >> ~/.bashrc



                      followed by



                      $source ~/.bashrc



                      and then test that it works



                      $python --version






                      share|improve this answer

















                      • 2




                        Duplicate of top answer
                        – wjandrea
                        Nov 30 at 14:41













                      up vote
                      -2
                      down vote










                      up vote
                      -2
                      down vote









                      Just write these two commands



                      $echo "alias python=python3" >> ~/.bashrc



                      followed by



                      $source ~/.bashrc



                      and then test that it works



                      $python --version






                      share|improve this answer












                      Just write these two commands



                      $echo "alias python=python3" >> ~/.bashrc



                      followed by



                      $source ~/.bashrc



                      and then test that it works



                      $python --version







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 30 at 13:55









                      Roshan Shah

                      71




                      71








                      • 2




                        Duplicate of top answer
                        – wjandrea
                        Nov 30 at 14:41














                      • 2




                        Duplicate of top answer
                        – wjandrea
                        Nov 30 at 14:41








                      2




                      2




                      Duplicate of top answer
                      – wjandrea
                      Nov 30 at 14:41




                      Duplicate of top answer
                      – wjandrea
                      Nov 30 at 14:41





                      protected by heemayl Mar 25 '16 at 17:01



                      Thank you for your interest in this question.
                      Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                      Would you like to answer one of these unanswered questions instead?



                      Popular posts from this blog

                      Mouse cursor on multiple screens with different PPI

                      Agildo Ribeiro

                      Sometime when accessing a menu: “Ubuntu 16.04 has experienced an internal error”