New Batch Starts on 16th Oct.
Module: Network Fundamentals (L2 L3 Protocol Testing)
Timing: 07:00 AM to 08:00 AM IST (Weekdays)
Sign Up Now !

Chapter 2: Setting Up Python

Before you can start writing and running Python code, you’ll need to set up Python on your computer. In this chapter, we’ll guide you through the process of installing Python on Windows, macOS, and Linux. We’ll also explain what an Integrated Development Environment (IDE) is and help you pick the one that suits you best. By the end of this chapter, you’ll have everything set up and ready to start writing Python code, no matter which operating system you’re using. Let’s get your Python environment up and running smoothly!


Table of Contents


How to Install Python

Python can be installed on various operating systems, including Windows, macOS, and Linux. Here’s a step-by-step guide to installing Python on each platform.

How to Install Python on Windows

1. Download the Installer: Visit the official Python website(https://www.python.org/downloads/) and download the latest version of Python for Windows.

2. Run the Installer: Locate the downloaded file and double-click to run the installer.

3. Customize Installation (Optional): You can choose the installation location and select optional features.

4. Add Python to PATH: Ensure the “Add Python to PATH” checkbox is selected before clicking “Install Now”.

5. Complete the Installation: Follow the prompts to complete the installation. You can verify the installation by opening Command Prompt and typing `python –version`.

How to Install Python on macOS

1. Download the Installer: Visit the official Python website(https://www.python.org/downloads/) and download the latest version of Python for macOS.

2. Run the Installer: Open the downloaded .pkg file and follow the prompts to install Python.

3. Verify the Installation: Open Terminal and type `python3 –version` to verify the installation.

How to Install Python on Linux (Ubuntu/ Debian/ Fedora)

Most Linux distributions come with Python pre-installed. However, you can install the latest version using your package manager.

Ubuntu/Debian:

1. Update the Package List: Open Terminal and run `sudo apt update`.

2. Install Python: Run `sudo apt install python3`.

Fedora:

1. Update the Package List: Open Terminal and run `sudo dnf update`.

2. Install Python: Run `sudo dnf install python3`.


What is an IDE?

You can create a Python script using any text editor, such as Notepad or Notepad++ on Windows, and Vim or Gedit on Linux devices. After creating the script, you can run it from the command prompt using the command “python <script name>”. However, a more convenient option would be to use an IDE. An Integrated Development Environment (IDE) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE typically consists of:

  • Code Editor: A text editor designed for writing and editing source code.
  • Debugger: A tool that helps in testing and debugging the code.
  • Compiler/Interpreter: Converts the written code into a format that can be executed by the computer.
  • Build Automation Tools: Tools that automate the process of compiling code and managing dependencies.

IDEs enhance productivity by offering various features like syntax highlighting, code completion, and version control integration. They provide a centralized interface with all the necessary tools for developing software, making the development process more efficient and streamlined.

Several IDEs are popular among Python developers, each with its unique features and capabilities:

  1. IDLE:
    • The default IDE that comes with the standard Python distribution.
    • It is simple and lightweight, suitable for beginners.
    • IDLE offers basic features like a code editor, interactive shell, and debugging tools.
  2. PyCharm:
    • Developed by JetBrains, PyCharm is one of the most popular IDEs for Python.
    • It offers advanced code editing, debugging, and testing features.
    • PyCharm comes in two versions: Community (free) and Professional (paid).
  3. Visual Studio Code (VS Code):
    • Developed by Microsoft, VS Code is a lightweight yet powerful source code editor.
    • It supports Python through extensions and provides features like debugging, syntax highlighting, and code navigation.
    • VS Code is highly customizable with a wide range of plugins.
  4. Spyder:
    • An open-source IDE specifically designed for data science and scientific computing.
    • It integrates well with libraries like NumPy, SciPy, and Matplotlib.
    • Spyder offers features such as an interactive console, variable explorer, and advanced editing capabilities.
  5. Jupyter Notebook:
    • An open-source web application that allows you to create and share documents containing live code, equations, visualizations, and narrative text.
    • It is widely used in data science and machine learning for its interactive and exploratory programming capabilities.

How to Use IDLE

IDLE (Integrated Development and Learning Environment) is the default Python IDE that comes with the Python installation. It provides a simple environment to start coding in Python.

Starting IDLE:

1. Open IDLE: After installing Python, you can find IDLE in your operating system’s application launcher. On Windows, it is listed in the Start Menu under Python. On macOS and Linux, you can search for IDLE in your applications.

A screenshot showing how to start the Python IDLE application from the application menu on a Windows machine.
opening IDLE from the start menu

2. Launch IDLE: Click on the IDLE icon to open it. You will see the Python Shell (interpreter) window.

A screenshot of Python IDLE application showing the interpreter mode.
IDLE interpreter mode

Using the Interpreter Mode

The Python Shell in IDLE allows you to enter and execute Python commands one line at a time. This is useful for testing small snippets of code and learning the basics of Python.

1. Enter a Command: Type a Python command at the prompt (`>>>`) and press Enter. For example, type `print(“Hello, World!”)` and press Enter. You should see the output `Hello, World!`.

Screenshot showing a 'Hello World' program in Python Interpreter mode in the IDLE application.
Running print("Hello World") in the IDLE Interpreter Mode

2. Experiment with Commands: You can try various commands and see the immediate results. This helps in understanding how different Python commands work.

Creating and Running Scripts

 IDLE also allows you to create and run Python scripts. This is useful for writing and testing more complex programs.

1. Create a New File: In the IDLE menu, go to `File > New File`. This opens a new window where you can write your Python code.

Screenshot showing how to create a new script file in Python IDE.
Creating a New Script File in IDLE

2. Write Your Script: Enter your Python code in the new file window. For example, write:

print(“Hello World”)

3. Save the File: Save your script by going to `File > Save` or pressing `Ctrl+S` (Cmd+S on macOS). Choose a location and name for your file, making sure it has a `.py` extension (e.g., `hello_world.py`).

4. Run the Script: To run your script, go to `Run > Run Module` or press `F5`. The output of your script will be displayed in the Python Shell window.

Screenshot showing how to run a script in Python IDLE.
Running a Python Script in IDLE

By using IDLE, you can easily start learning Python by experimenting with commands in the interpreter mode and writing scripts for more complex tasks.


In this chapter, we discussed how to install Python on different operating systems and introduced what an IDE is, along with some popular ones used for Python development. We also covered how to use IDLE, the default IDE that comes with Python, for running commands in the interpreter mode and creating scripts. In the next chapter, we will go through Python basics, including how to create variables and use the print function in the interpreter mode. Be sure to check out the next chapter for these fundamental concepts!


Next >>> Chapter 3: Working with Variables in Python

Previous >>> Chapter 1: Introduction to Python Programming


We’d love to hear your feedback and suggestions about this article. Feel free to reach out to us using the WhatsApp number below.

Sajith Achipra has been a trainer and testing consultant at Zframez Technologies since 2009. With 15+ years of experience, he specializes in networking, Python, development, and testing. He conducts online courses to help students and professionals enhance their skills. You can reach him on WhatsApp at +91 8884 884 844 for your training and testing requirements.