Skip to main content

Python Installation

Python is a cross-platform programming language, which means it can run on multiple platforms such as Windows, macOS, Linux and has even been ported to Java and .NET virtual machines.

Let's how you can install Python on your PC.

Install Python on Windows

  1. Download the latest version of Python from the official download page.

  2. Run the installation file and follow the steps to install Python.

note

During the installation process, select Add Python to environment variables. This will add Python to environment variables and you will be able to run Python from anywhere on your computer.

Python Installation Add Python Environment Variables

Once the installation process is finished, you can run Python.

Common Issue: 'python' is not recognized

If you see the following output from the Command Prompt after typing the python command:

'python' is not recognized as an internal or external command, operable program or batch file.

It is likely that you did not check the Add Python to environment variables box when installing Python.

To resolve this error, follow the steps below:

  1. Find the folder with the installed version of Python as its name in X:\Program Files. (where X is the drive where Windows is installed; e.g.,C:\Program Files\Python310). If this folder does not exist, it means that you have not installed Python.
  2. Open this folder and copy its path.
  3. Right-click on This PC, then go to Properties => Advanced system settings => Environment variables.
  4. In the window that appears when a path variable exists, select it, ​and click Edit; otherwise, click New.
  5. In the next dialogue box, click on New and paste the previously copied path of the folder; then, click OK.

Install Python on macOS

It’s recommended to install Python on macOS using an official installer.

  1. Download a Python release for macOS.
  2. Run the installer by double-clicking the installer file.
  3. Follow the on-screen instructions and click the Next button until the installation is complete.

Install Python on Linux

Often python 3 is already included in your Linux distribution. To check if python is already installed run the following command in the terminal:

python3 --version

If you see a response with the version of Python, then your computer already has Python 3 installed.

Otherwise, you can install Python 3 using a package management system. For example, we can install Python 3.10 in Ubuntu using APT and following these steps:

  1. Install the required dependency for adding custom PPAs.

    python3 --version
  2. Then add the deadsnakes PPA to the APT package manager sources list as below.

    sudo add-apt-repository ppa:deadsnakes/ppa
  3. Press Enter to continue.

    ..........
    To install 3rd-party Python modules, you should use the common Python packaging tools. For an introduction into the Python packaging ecosystem and its tools, refer to the Python Packaging User Guide:
    https://packaging.python.org/installing/

    Sources
    =======
    The package sources are available at:
    https://github.com/deadsnakes/

    Nightly Builds
    ==============

    For nightly builds, see ppa:deadsnakes/nightly https://launchpad.net/~deadsnakes/+archive/ubuntu/nightly
    More info: https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa
    Press [ENTER] to continue or ctrl-c to cancel adding it
  4. With the deadsnakes repository added to your Ubuntu O.S., now download Python 3.10 with the single command below.

    sudo apt install python3.10
  5. Dependecy tree: type y and press Enter

    ...................
    Building dependency tree
    Reading state information... Done
    The following additional packages will be installed:
    libpython3.10-minimal libpython3.10-stdlib python3.10-minimal
    Suggested packages:
    python3.10-venv binfmt-support
    The following NEW packages will be installed:
    libpython3.10-minimal libpython3.10-stdlib python3.10 python3.10-minimal
    0 upgraded, 4 newly installed, 0 to remove and 192 not upgraded.
    Need to get 5,023 kB of archives.
    After this operation, 19.7 MB of additional disk space will be used.
    Do you want to continue? [Y/n] y
  6. Verify the installation by checking the installed version.

    python3 --version

Try you first Python program

Let's create a very simple program that outputs Hello, World! on the screen.

Type the following code in any text editor or an IDE and save it as hello_world.py

print("Hello, world!")

Then, run the file and you will get the following output:

Hello, world!
note

Once Python is installed, typing python in the command line will invoke the interpreter in immediate mode. Here, you can directly type in Python code, and press Enter to get the output.

Otherwise, you can use any text editing software (or even better an IDE) to write a Python script file.