First check if Python is already installed on the machine or not. Just type the command “python” and check the response-
$ python
Python 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
BashIf nothing is found then you can try using the command “python3” as you might have Python version 3 installed and the execution file is named “python3”.
$ python3
Python 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
BashIf it shows some output of the Python version and opens an interactive Python shell, we already have Python installed on our machine. We do not need to do anything.
NOTES
Once you are inside the Python interactive shell, then type “exit()” and press Enter to get out of the shell.
If not already installed, then we might get output like below-
$ python
sh: 29: python: not found
BashLet’s see how we can install and run Python on different operating systems.
Python Installation on Linux
We are installing Python on a Debian-based operating system. First, pull all the updates-
sudo apt update
BashUse the following command to install Python version 3-
sudo apt install python3
BashCheck the installed version of Python using the following command-
python3 --version
# Output:
# Python 3.10.12
BashInstall PIP for Python package management-
sudo apt install python3-pip
BashAs we have installed Python version 3 here, the executable is named “python3”. We can create an alias of “python3”, so that we can call the “python3” command easily using just “python”.
Use the following command to add the alias to “.bashrc” file-
echo "alias python=python3" >> ~/.bashrc
BashUse the following to load the changed alias-
# Then use the following command to load the changed source
source ~/.bashrc
# Or restart the terminal
BashPython Installation on Windows
NOTES
All Python downloadable versions are available on the official site. Use the following link for any download-
Download the appropriate installer from the above link, then run the installer. You will see a screen like below-
The installation process is simple. just follow the instructions and click on the button/link of the next step.
NOTES
Make sure to check the box for the option “Add python.exe to PATH“.
This is important, to check it box, so that the Python executable path is added to the PATH environment variable of Windows, and we can use the “python” command from anywhere.
Check the Python installation using the command “python”-
> python
Python 3.13.0 (tags/v3.13.0:8e8a4ba, Jun 6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
PowerShellPython Installation on MacOS
NOTES
All Python downloadable versions are available on the official site. Use the following link for any download-
Download the installer, and run it-
Follow the instructions and complete all the steps in the installer-
NOTES
If you are using Homebrew then run the following command to install Python-
brew install python
Bash