Python environment setup

In this post, you'll learn how to setup an environment for Python to execute or run a Python program.

How to Run or Execute a Python Program

To execute a Python program, generally you've got two options, as given below:

  1. Python IDLE can be used to directly execute a Python program.
  2. Execute a Python program using any Python IDE like PyCharm.

Note: In this series of Python tutorials, all the programs are created and executed using the PyCharm IDE.

Now the question is, why use PyCharm? Here is a list of some answers that may satisfy this question:

Note: Under intelligent coding assistance, we'll get completion and inspections of code, as well as on-the-fly error highlighting and many other things that come under this feature and that help you a lot while coding. I've been using this IDE for about 4-5 years.

The only disadvantage of PyCharm IDE from my perspective is that it takes up around 600–800 MB of space on your computer. Here is a snapshot of the folder's properties, where the installed PyCharm IDE is available, showing the total space taken:

python pycharm environment setup

But you need not worry about the size. Because if you have a PC with fewer specifications, such as less available storage space,I've got a solution in that case. The solution is Python IDLE. It takes around 20–30 MB of space and is able to execute Python programs directly. Install Python IDLE as described below in this tutorial, and follow all the steps to setup the environment using this very lightweight Integrated Development Environment for Python.

Python IDLE Environment Configuration

Python software must be installed on your PC in both cases, whether you are executing Python code directly in Python IDLE or through the PyCharm IDE.That is, Python software is necessary to be available on your PC to execute any Python code, either directly in IDLE or using any virtual IDE like PyCharm, Eclipse, PyDev, Spyder, etc.

Therefore, follow all the steps given below, one by one, to install and setup Python IDLE so that you can run or execute your Python code.

Python IDLE Setup, Step No. 1

Because the most recent Python version was 3.9.6 when I wrote this post.Therefore, I've downloaded this development software from the Internet. But I recommend that you download the very latest version of Python from the Internet. That is, get the most recent Python version from the Internet.

Note: Download only from the official website, "python.org."

Attention: Don't visit any unknown website.

That is, navigate to python.org. The following is a screenshot of the opened website:

python environment setup

As indicated above, click on the Download button from the main navigation to open the download page that looks like this:

python environment setup windows

As again indicated above, click on "Download Python 3.9.6" (this version gets changed at the time you visit if the latest version arrives). The download gets started after clicking on this button. The size may be around 20–30 MB.

Install the Python software on your system. After installation, follow the steps given below.

Python IDLE Setup, Step No. 2

If you've got Windows 7, then go to Start -> All Programs -> Python 3.9 -> IDLE (Python 3.9, 64-bit). If you've got 32-bit Windows, then in place of 64-bit, you'll see 32-bit.

If you've got Windows 10 (32-bit or 64-bit), then go to Start -> Python 3.9 -> IDLE (Python 3.9 64-bit). Follow the same steps to open the Python IDLE on any system, such as Linux, Apple Mac, or Windows. Here is the snapshot:

python environment

Here is a screenshot of the Windows IDLE Shell 3.9.6. The windows opened after clicking on IDLE (Python 3.9, 64-bit) as told above:

setting up environment python

Now let's create and execute a Python program using this Python shell directly. Follow the next step.

Python IDLE Setup, Step No. 3

As soon as the Python Shell windows appear, navigate to or click on "FILE -> NEW FILE," as shown in the screenshot below:

python environment setting

A new window opened after navigating as described above. Now type the following code in that window:

print("Hey!, Welcome to codescracker.com")

like shown in the snapshot given below:

python setup windows

As the simplest Python code is written, now save the code by navigating File -> Save As..., as shown in the snapshot given below:

python idle setup window

Here is the window opened after navigating as described above:

run a python program using python idle

As shown in the above snapshot, type the name of the program, say, codescracker.py, and press the ENTER key. Now your Python source code is saved. Step 4 is outlined below.

Python IDLE Setup, Step No. 4

Since the Python source code is saved, now is the time to execute or run the program. To do this, either navigate to Run - > Run Module (F5) or just press the F5 key to run the program. Here is the output produced:

python run a program idle

Let's write some more Python code and run it. Here is the code:

print("Printing \"codescracker.com\" 10 times\n")
for i in range(10):
    print("codescracker.com")

Write this code and press the F5 key to run it. Here is the output produced:

python idle environment setup

Since this is just a demo of how a Python program can be executed, Therefore, don't worry about the code. Later on, you'll learn how it works step by step.

Now you're able to execute Python code directly using Python IDLE. Therefore either you can proceed with it only, or follow the next direction to execute Python code using one of the famous Python IDE named PyCharm.

Note: In both cases, Python software is needed.

Execute a Python program using the PyCharm IDE

Download PyCharm from the Internet and install it. After installing, navigate to Start -> JetBrains -> PyCharm Community Edition. Here is a snapshot of the initial windows of PyCharm:

python pycharm setup

Click on "New Project." Here is the newly opened window:

pycharm setup python

As indicated above, type codescracker in the Location field and click on the Create button. Again, a new window gets opened. As a result, go to Project -> codescracker -> Right Mouse Click -> New -> Python File as shown in the snapshot below:

execute python program using pycharm

A new small window gets opened, as shown in the snapshot below:

pycharm python program run setup

As shown above, enter the name codescracker.py and press the ENTER key. The file is now created.Now type your Python code again. Here is the snapshot after typing the Python code:

python environment setup pycharm

To execute this code, go to Run -> Run -> ENTER key or press Shift + F10 key and then ENTER key. The program written in the same file will no longer require the user to press the ENTER key after pressing Shift + F10 to run.

Python Online Test


« Previous Tutorial Next Tutorial »


Liked this post? Share it!