Skip to content
VLSI Mentor

Python Part I · Module 1 · Introduction to Python

Checking Python Is There, and Which Version

Before writing a file you need to know that Python is actually available and which one you are getting, and on an engineering machine those are two genuinely separate questions. A shared compute server may have several Python installations, the command named python may be an old version or may not exist at all, and the one your shell finds may not be the one your colleague's shell finds. None of this is complicated once you know the two commands that answer it. This chapter gives you those commands, shows what each possible answer means, and tells you what to do in the awkward cases — without turning into an operating-system installation manual that would be out of date within a year.

Foundation8 min readPythonPart IFundamentalsTerminalEnvironment

Part I · Module 1 · Chapter 1.6 · Checking Python Is There, and Which Version

1. The One Command

Open a terminal and type:

Azvya Education Pvt. Ltd.VLSI Mentor
Snippet
python3 --version

If Python 3 is installed, you get one line back:

Azvya Education Pvt. Ltd.VLSI Mentor
Snippet
Python 3.11.4

Your numbers will differ. Anything starting Python 3. is fine for this entire course.

The --version part is an instruction to the program: do not start up, just tell me what you are and stop. Most command-line tools accept it.

2. What the Answer Tells You

What you sawWhat it meansWhat to do
Python 3.8 or newerPython 3 is installed and usableContinue to Chapter 1.7
Python 3.6 or 3.7Python 3, but oldUsable for Part I; ask about a newer one
Python 2.7.xPython 2 — a different, retired languageSee §4
command not foundNo program by that name on your pathSee §5

3. python and python3 Are Not the Same Question

This is the part worth reading carefully, because assuming otherwise is a genuine time-waster on shared machines.

There may be two separate commands, python and python3, and they are not guaranteed to be the same program. Historically python meant Python 2 and python3 meant Python 3. That transition is long finished, but engineering machines are long-lived, and you will still meet systems where:

  • python is Python 2, and python3 is Python 3 — the classic older-system layout;
  • python does not exist at all, and only python3 does — common on modern Linux;
  • python is Python 3, and python3 also exists as the same program — common on newer systems and in virtual environments;
  • both exist and are different Python 3 installations — common on compute farms with several tool versions.

So ask about them separately:

Azvya Education Pvt. Ltd.VLSI Mentor
Snippet
python --version
python3 --version

Two answers, possibly different. Neither one implies the other.

4. If You Got Python 2

Python 2 reached end of life in January 2020. It receives no fixes, and it is a genuinely different language — code written for Python 3 frequently will not run on it, and the error you get rarely says "wrong version".

If python --version reports Python 2, that is not a problem as long as python3 reports Python 3. Simply use python3 and ignore the other one. That situation is normal on older engineering systems and nothing needs fixing.

If python3 is also missing, treat that as "not installed" and read the next section.

5. If Nothing Was Found

command not found means your shell looked through the places it searches and found no program with that name. That does not necessarily mean Python is absent from the machine — it may be installed somewhere your shell is not looking.

On an engineering system, try in this order:

  1. Ask what your shell can see. This reports the full path of the program that would run, or nothing at all:

    Azvya Education Pvt. Ltd.VLSI Mentor
    Snippet
    which python3
    Azvya Education Pvt. Ltd.VLSI Mentor
    Snippet
    /usr/bin/python3
  2. Check whether a module system is in use. Many compute farms make tools available on request rather than by default. If your site uses environment modules, module avail python will list what can be loaded. Your site's own documentation is the authority here — the exact command varies.

  3. Ask. On a managed corporate or university machine you may not be able to install software yourself, and the answer is a request to whoever administers it. That is a normal thing to ask for.

  4. On your own machine, install it from python.org, which has current instructions for every platform. This course deliberately does not reproduce them: installation steps change, and a copy here would quietly go stale.

6. Which One Am I Actually Getting?

One more command, worth knowing now and genuinely useful later:

Azvya Education Pvt. Ltd.VLSI Mentor
Snippet
which python3
Azvya Education Pvt. Ltd.VLSI Mentor
Snippet
/usr/bin/python3

This shows the full path of the program your shell will run. It matters when a machine has several Python installations — a system one, a tool-provided one, a project-specific one — and you need to know which of them you just used.

You do not need this today. You will need it the first time a script works in your terminal and fails in someone else's, and at that point remembering this command saves a long afternoon.

7. Exercise

Exercise 1 — survey your machine. Run all four commands and write the answers down:

Azvya Education Pvt. Ltd.VLSI Mentor
Snippet
python3 --version
python --version
which python3
which python

Then answer in one sentence: are python and python3 the same program on this machine, and how do you know?

Exercise 2 — predict the failure. A colleague sends you a note saying "just run it with python". On a machine where python is Python 2, predict whether the failure message will mention the version. What does your answer suggest about how helpful that error will be?

Exercise 3 — read the path. If which python3 returned something under /usr/bin/, and a colleague's returned something under a tool directory, name one thing that could differ between your two runs of the same script.

8. Summary

  • python3 --version is the check. One line back means Python is installed and tells you which version.
  • Anything Python 3.8 or newer works for this entire course.
  • python and python3 are separate questions. They may be different programs, different versions, or one may not exist. Ask about each.
  • Python 2 is a retired, different language. If python is Python 2 and python3 is Python 3, just use python3 — nothing is broken.
  • command not found means your shell could not find it, not necessarily that it is absent. Check which, check whether your site uses modules, then ask or install.
  • which python3 tells you which one you actually got — the command you will want the first time a script behaves differently on two machines.

You now know Python is there and which one you are running. The next chapter is the one everything so far has been leading to: you write a file and run it.

Where this fits

Part of the Python curriculum.