How to remove Python 2.7 and install Python 3.x?

Asked by g2

How do I remove Python 2.7 so that I can install Python 3.1 or 3.2 and develop software on the latest version?

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu python3-defaults Edit question
Assignee:
No assignee Edit question
Solved by:
Eliah Kagan
Solved:
Last query:
Last reply:
Revision history for this message
actionparsnip (andrew-woodhead666) said :
#1

What is the output of:

lsb_release -a

Thanks

Revision history for this message
Best Eliah Kagan (degeneracypressure) said :
#2

You don't have to remove python 2.7 to install a 3-series python. They coexist together quite well. You can just install the package called python3. You can then run it with the command python3. You can make your programs run with python3 when they are run as executable files using any of several "hashbang" constructs, which would be highly advisable even if python3 were your only python (at least if you plan to distribute any of your programs). One good way to do this is to make the first line of each python source code file (that you intend to ever have executed, rather than only ever being imported by other source files):

#!/usr/bin/env python3

You might find that python3 is already installed. I recommend you see what happens when you run:

python3

You could remove python 2.7 by removing the python-2.7, python-2.7-minimal, and libpython2.7 packages (it's possible that not all three are installed). But you should almost certainly not do this, because python2.7 is depended on by many core components of Ubuntu and many applications. Removing it would probably remove many other packages, and render some others nonfunctional. Since removing python2.7 is not necessary or even helpful in installing and using python3, I strongly recommend against it.

Revision history for this message
g2 (gcvesely) said :
#3

Thanks Eliah Kagan, that solved my question.

Revision history for this message
g2 (gcvesely) said :
#4

#3

Thanks Eliah Kagan, that solved my question.

I had downloaded and installed Python 3.2, but I did not understand that I had to type "python3" to get it to run. I typed "python" and got 2.7 and assumed it did not install properly. Sorry for being so "thick". I owe you a Jamba Juice!