10

I need it for learning Python language. Please Help!

Mervin Jacob
  • 441
  • 1
  • 4
  • 8

3 Answers3

14

By default, both python2 and python3 are installed.

As already mentioned, you can check your version with either:

python -V

(mind the capital) or

python --version

or

apt-cache policy python

However

This will only show the version of python2, while on 14.04, python3 is installed as well. To see the version of python3, simply replace all occurrences of python in the commands above by python3

Note

If you start coding, also mind that using:

python <script>

will make python 2 run the code, and

python3 <script>

will make python 3 run it, and (if the script is executable), the shebang

#!/usr/bin/env python

will run it in python 2, and

#!/usr/bin/env python3

will run it in python 3

Using Idle

As an answer to what you asked in a comment: So it is the "terminal" where we do the coding,right!?

The most convenient way is to use Idle (from the repositories). You can then test-run the code with F5, or if necessary from the terminal. It has the advantage that indentation is suggested automatically (a.o.)

Mind that you need to use different version of Idle for python 2 and 3.

Jacob Vlijm
  • 82,471
  • 12
  • 195
  • 299
  • Hi Jacob, I think your comment is the only answer this question needed. This is too detailed and misses the focus your comment has. Anyway, wanted to share it with you. Sometimes a one-line answer is enough. Your expertise can then be spent on other questions. – don.joey May 30 '15 at 08:40
  • @don.joey I was doubting, you might be right :). However, the additional question element below Maythux answer made me think it is useful to add a few things... – Jacob Vlijm May 30 '15 at 08:43
  • So is "Idle" an application!? – Mervin Jacob May 30 '15 at 09:08
  • Yes, it is a IDE for python, see the link in the answer: http://en.wikipedia.org/wiki/IDLE_%28Python%29. You can install it (both Idle (2) and Idle3 from the software center. – Jacob Vlijm May 30 '15 at 09:15
4

Check your python version with

python --version

Also note that there are some severe differences between python 2 and 3. https://wiki.python.org/moin/Python2orPython3

Ben
  • 603
  • 5
  • 14
  • 4
    You might want to add `python3 --version`, since it is installed by default as well. `python --version` only shows version of 2 – Jacob Vlijm May 30 '15 at 08:08
3

Python is installed by default in Ubuntu, but to check it:

Run this command

$ apt-cache policy python


python:
  Installed: 2.7.3-0ubuntu2.2
  Candidate: 2.7.3-0ubuntu2.2
  Version table:
 *** 2.7.3-0ubuntu2.2 0
        500 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main amd64 Packages
        100 /var/lib/dpkg/status
     2.7.3-0ubuntu2 0
        500 http://us.archive.ubuntu.com/ubuntu/ precise/main amd64 Packages

Thanks to @JacobVlijm note if you use Ubuntu >12.10 then you should use apt-cache policy python3 instead

As you see under pyton section you can see Installed: 2.7.3-0ubuntu2.2 This means it's installed and the version is 2.7

Also the candidate shows you the latest version available in your software channel, so you can upgrade your version if you want.

Maythux
  • 82,867
  • 54
  • 239
  • 271
  • 3
    You might want to add `apt-cache policy python3` since `apt-cache policy python` only shows python2, while python3 is installed as well on 12.10 > – Jacob Vlijm May 30 '15 at 08:04
  • Installed: 3.4.0-0ubuntu2 Candidate: 3.4.0-0ubuntu2 This is what it is showing after using this command `apt-cache policy python3`. So it means I have the latest 3.4.0 right!? – Mervin Jacob May 30 '15 at 08:19
  • @MervinJacob That is correct. – Jacob Vlijm May 30 '15 at 08:22
  • As I told you guys I need Python for programming. So it is the "terminal" where we do the coding,right!? – Mervin Jacob May 30 '15 at 08:32
  • @MervinJacob the Python REPL is nice. REPLs are nice in general. I don't think you want to code an enterprise-grade application in the terminal, though. You should clarify what you have actually set to achieve. (Also, I smell homework, if so you might want to ask your teacher or TA directly). – Tobia Tesan May 30 '15 at 15:21
  • @TobiaTesan I am planning to join "Programming for Everybody (Python)" by Coursera (http://www.coursera.org/course/pythonlearn/). They will give detailed instructional videos for both Windows and Macintosh computers for all software installation but not for Linux. So that why I had soo many doubts! – Mervin Jacob May 31 '15 at 17:35
  • Guys should I use 'Visual Studio Code'!? – Mervin Jacob May 31 '15 at 19:13
  • @MervinJacob: use whatever you like/whatever is required by your instructor. Without specific requirements, any editor is as good as any other. After all, Emacs and Vim fanboys have been arguing with each other for more than 20 years (which is funny since Emacs is clearly the superior choice :P ). I think this is not relevant to the question. StackExchange is *not* a forum; in fact "Can Visual Studio do X" is probably another question. – Tobia Tesan Jun 06 '15 at 16:46