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:
python3 --versionIf Python 3 is installed, you get one line back:
Python 3.11.4Your 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 saw | What it means | What to do |
|---|---|---|
Python 3.8 or newer | Python 3 is installed and usable | Continue to Chapter 1.7 |
Python 3.6 or 3.7 | Python 3, but old | Usable for Part I; ask about a newer one |
Python 2.7.x | Python 2 — a different, retired language | See §4 |
command not found | No program by that name on your path | See §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:
pythonis Python 2, andpython3is Python 3 — the classic older-system layout;pythondoes not exist at all, and onlypython3does — common on modern Linux;pythonis Python 3, andpython3also 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:
python --version
python3 --versionTwo 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:
-
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 MentorSnippetwhich python3Azvya Education Pvt. Ltd.VLSI MentorSnippet/usr/bin/python3 -
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 pythonwill list what can be loaded. Your site's own documentation is the authority here — the exact command varies. -
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.
-
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:
which python3/usr/bin/python3This 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:
python3 --version
python --version
which python3
which pythonThen 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 --versionis the check. One line back means Python is installed and tells you which version.- Anything
Python 3.8or newer works for this entire course. pythonandpython3are 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
pythonis Python 2 andpython3is Python 3, just usepython3— nothing is broken. command not foundmeans your shell could not find it, not necessarily that it is absent. Checkwhich, check whether your site uses modules, then ask or install.which python3tells 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.
