Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

If I open Terminal and type in python, I see the version is 2.7.4. How do I get python 3.4? And do I need IDLE if I have sublime text?

share|improve this question
    
This is a duplicate of askubuntu.com/questions/350751/… –  don.joey Apr 18 at 9:31
2  
@don.joey: No, it's not a duplicate as 14.04 already has python 3.4 installed by default. –  Florian Diesch Apr 18 at 12:11
    
@FlorianDiesch I thought 13.04 also came with python 3 installed by default. –  don.joey Apr 18 at 12:33

5 Answers 5

up vote 22 down vote accepted

python 3.4 is installed on the stable release of Ubuntu 14.04. You need to use python3 to use python 3.4. For example, to compile a script file.py, use:

python3 file.py

This will use python 3.4 to interpret your program or you can use the shebang to make it executable. The first line of your program should be:

#!/usr/bin/env python3

and then use chmod +x file.py to assign executable permissions and then run your python script as ./file.py which would use python3 to execute.

If you want python3 to be used when you type python on the terminal, you can use an alias. To add a new alias, open your ~/.bash_aliases file using gedit ~/.bash_aliases and type the following:

alias python=python3

and then save and exit and type

source ~/.bash_aliases

and then you can type

python file.py

to use python3 as your default python interpreter.

No, you don't need IDLE just to use python3 to interpret your programs.

share|improve this answer
    
Thanks. Is there a way to avoid typing "~/Dropbox/XXX/Pythonfiles/examplefile.py" when I want to interpret a Pythonfile (for instance "examplefile.py"? –  empedokles Apr 18 at 9:39
    
BTW: I couldn't find the .bash_aliases file in my file manager. –  empedokles Apr 18 at 9:50
    
1) You can just go that directory(~/Dropbox/XXX/Pythonfiles/) first and then type python examplefile.py(this might be pretty dumb and not what you expected). 2) You could alias python ~/Dropbox/XXX/Pythonfiles/examplefile.py as a whole to a command which would execute when you type in the custom aliased command. 3) You won't find if you didn' have any aliases before, that is absolutely fine, you can create one. –  i08in Apr 18 at 10:01
    
What's the command to create this .bash_aliases file in terminal? –  empedokles Apr 18 at 10:04
    
Thanks this worked. Is chmod +x file.py for all files or do you mean the individual pythonfile? –  empedokles Apr 18 at 11:19

On Ubuntu 14.04 Python 3.4 is installed by default.

As recommended by PEP-394 you can use python and python2 to run Python v2 (2.7) and python3 to run Python v3 (3.4).

share|improve this answer
    
how to make python 3.4 default for Netbeans IDE ? now it is 2.7.6 when I click auto detect it will not 3.4.1 not detecting in python platform manager(Netbeans IDE 8.0.1) –  ARUL Sep 19 at 11:59

You should already have it install:

python3 -V

To install idle 3:

sudo apt-get install idle-python3.4
share|improve this answer

Python3.4 is already installed on your system, you just need to call it with python3 instead of python

share|improve this answer

In the terminal type: python3

The terminal will itself say to type:

sudo apt-get install python3-minimal

Do it and this will install Python 3.2.3.

Then in the terminal type: python3.4 -- you shall enter Python 3.4.1.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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