avatarSue Lynn

Summary

The provided content is a comprehensive guide on setting up a Python environment on a Windows computer, including downloading Python from the official website, installing it with the option to add it to the system PATH, and an introduction to using Python IDLE for writing and executing Python scripts.

Abstract

The guide begins by directing users to download the latest Python 3 release from the official Python website for Windows. It emphasizes the importance of selecting the correct installer based on the system's architecture (32-bit or 64-bit). During installation, it instructs users to check the option "Add Python 3.9 to Path" to enable Python to be run from the command prompt. After successful installation, confirmed by a "Setup was successful" message, the guide introduces Python IDLE, an integrated development and learning environment that comes with Python. It explains the two main components of IDLE: the Shell Window for interactive Python sessions and the Editor Window for writing and saving Python scripts. The guide also covers how to configure IDLE settings, such as fonts, themes, and window preferences, and demonstrates how to run a Python script from the Editor Window using the "Run Module" option. The article concludes by acknowledging that while Python IDLE is a suitable starting point for beginners, advanced users may eventually transition to more sophisticated tools like Pycharm, Eclipse, or Microsoft Visual Studio.

Opinions

  • The guide suggests that adding Python to the PATH variable simplifies the process of running Python scripts from the command prompt.
  • It is implied that using the latest Python 3 release is preferable, as indicated by the instruction to select the latest version available at the time of writing (Python 3.9.6).
  • The guide expresses a preference for the Dark theme in Python IDLE, stating it is soothing for the eyes, which may suggest a consideration for user comfort during extended coding sessions.
  • The article conveys that while Python IDLE is sufficient for beginners, it encourages users to explore other development environments as they become more proficient in Python programming.

Guide to Setup Python Environment & Understanding Python IDLE

Creating the environment for your first Python code and start coding

Photo by Hitesh Choudhary taken from Unsplash

Introduction

Setting up a Python environment on your computer is the first step before starting your first python script. There are many approaches you can begin with the setup and installation but in this article, we will learn to set up our Python environment by downloading from the official python distributions — python.org. After setting up our Python environment we will understand more about Python IDLE that comes bundled together with your Python installation. (* OS used in this tutorial is on Windows)

Let’s start setting up our Python Environment!

Step 1 — Navigate to the python.org downloads page for Windows.

Python download page for Windows

Step 2 — Select the latest Python 3 Release (As of this article, the latest Python version is Python 3.9.6)

Select the Latest Python 3 Release

Step 3 — Scroll to the bottom of the page, select and download Windows x86–64 executable installer for 64-bit (If your PC is using 32-bit then select the installer Windows x86 executable installer for 32-bit)

Select and download Windows Installer

Step 4 — Run the installer by double click on the downloaded file

  • A dialog box will pop up after you run the Python windows installer
Python Install — Dialog Box
  • Check the box “Add Python 3.9 to Path” (This box is unchecked by default)

By adding Python to PATH allows you to run Python from your command prompt (cmd). In summary, you can run Python script from your command prompt by just typing “python”.

Check the Option — Add Python to Path

Step 5 —Click “ Install Now”

Python Installation

If your installation is successful, you will receive the message “Setup was successful”

Python Installation — Setup successful message

Step 6 — Under the Windows Search bar, enter “Python” and Select IDLE (Python 3.9 64-bit)

Windows search bar: python

The IDLE shell window will open up and you can begin writing your first Python script.

Python IDLE shell

Step 7 — Write your first Python Script (“Hello, World!”)

Print “Hello, World!” on Python IDLE shell

Well done! You now have your Python environment installed on your computer and written your first Python scirpt. Next part of this article, we will understand more about Python IDLE.

What is Python IDLE?

Python IDLE is a Python development and learning environment and IDLE stand for:

There are two main windows, which are the “Shell Window” and the “Editor Window”. The “Shell Window” provides access to Python interactive mode and the “Editor Window” allows you to create or edit from existing python files. Let’s first see how we can configure our Python IDLE environment.

In your IDLE shell environment, navigate to Options → Configure IDLE.

Configure IDLE

The “Settings” menu will pop out and the tab “Fonts/Tabs” shows a list of fonts you can select and font size for your Python IDLE environment.

IDLE — Settings Menu : Fonts / Tabs

On the “Highlights” tab, you can select a theme for your Python IDLE environment. For example, I will switch to a Dark them as it is more soothing for our eyes.

IDLE — Settings Menu: Highlights

The “Windows” tab is where you can specify your Window Preferences such as width, height, etc. But let’s take note of the Window preference upon startup which by default is “Open Shell Window”.

IDLE — Settings Menu: Windows

In the earlier section where we open “IDLE (Python 3.9 64-bit)” from the window search bar, by default the IDLE “Shell Window” opens up as the option “Open Shell Window” was selected by default in the settings. But what happens if the option “Open Edit Window” is selected? — Let’s try selecting this option and observe the difference.

IDLE — Settings Menu: Windows — Switch to “Open Edit Window”

Observe the difference when the “Open Edit Window” option is selected with the “Shell Window”. The “Shell Window” displays information about the version of the Python installed and the operating system where else the “Edit Window” is an empty file.

Python IDLE “Shell Window” and “Edit Window”

The “Shell Window” is an interactive environment and is useful when you only need to execute one line of command but will not be practical if you are writing a full python program. Therefore, the “Edit Window” will be more useful as you can write your Python scripts and save the code. Let’s look at an example of printing the “Hello, World!” message using “Edit Window”.

Python IDLE “Edit Window”

Notice that the “Edit Window” does not run the script upon entering. To run the script, you will need to navigate to Run → Run Module.

Python IDLE “Edit Window” — Run Module

A dialog message will pop up requesting that the file must be saved. Save the Python file with your preferred file name (Ensure the file is saved with the .py extension). Upon saving, your Python file will be executed and the result will be printed in an IDLE “Shell Window”

Result of Python script displayed in IDLE “Shell Window”

Conclusion:

Setting up your own Python environment is easy and only requires few steps and you may start working on your first Python script. As a beginner learning Python, Python IDLE can be a great place to begin your journey. However, as you advance further you will explore other tools such as Pycharm, Eclipse, Microsoft Visual Studio, etc. Nonetheless, congrats on your first exploration with Python!

References & Links

[1] https://realpython.com/installing-python/

[2] https://realpython.com/python-idle/

[3] https://geek-university.com/python/idle-editor/

Python
Programming
Machine Learning
Data Science
Software Development
Recommended from ReadMedium