Python Environment Setup
In this tutorial, you'll learn how to setup 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 two options, as given below:
- Execute Python program directly using Python IDLE
- Execute Python program using any Python IDE like PyCharm
Note - In this series of Python tutorial, all the programs are created under and executed using PyCharm IDE.
Now the question is, why to use PyCharm ?. Here are the list of some answers, that may satisfy this question:
- It is free
- It is lightweight
- Best suited for Python
- Offers much more functionality for Python programming
- It makes development easier and productive
- Offers many built-in developer tools
- And the most important feature is, it provides intelligent coding assistance.
Note - Under intelligent coding assistance, we'll get completion and inspections of code, and also on-the-fly error highlighting and many more things comes under this feature, that helps you a lot while coding. Even I'm using this IDE since 4-5 years.
The only disadvantage of PyCharm IDE in my perspective is, it takes around 600-800 MB of spaces in your computer system. Here is the snapshot of the folder's properties, where the installed PyCharm IDE is available, showing the total space taken:
But you need not to worry about the size. Because if you've a PC with less specification like less storage space available. I've a solution in that case. The solution is Python IDLE. It takes around 20-30 MB of space and is able to execute Python program directly. Install Python IDLE as told below in this tutorial and follow all the steps to setup the environment using this very lightweight Integrated Development Environment for Python.
Environment Setup using Python IDLE
In both the cases, that is, executing Python codes using directly Python IDLE or using PyCharm IDE, Python software need to be installed on your PC. That is, Python software is necessary to be available in your PC to execute any Python code either using directly the IDLE, or using any virtual IDE like PyCharm, Eclipse, PyDev, or Spyder etc.
Therefore, follow all the steps given below one by one, to install and setup Python IDLE so that you becomes able to run or execute your Python code.
Python IDLE Setup - Step No.1
Since, right now the latest Python version is 3.9.6. Therefore I've downloaded this development software from Internet. But I recommend you to download the very latest version of the Python from Internet.
That is, download latest Python from Internet.Note - Download only from the official website "python.org".
Attention - Don't visit any unknown website.
That is, open the website python.org. Here is the snapshot of the opened website:
As indicated above, click on the Download button from main navigation to open the download page that looks like:
As again indicated above, click on the Download Python 3.9.6 (this version gets changed at the time when you visit, if latest version arrives). The download gets started after clicking on this button. The size may be around 20-30 MB
Now install the software Python in your system. After installation, follow the steps given below
Python IDLE Setup - Step No.2
If you've Windows 7, then go to Start -> All Programs -> Python 3.9 -> IDLE (Python 3.9 - 64 bit). If you've 32-bit Windows, then in place of 64-bit, you'll see 32-bit
If you've Windows 10 (32-bit or 64-bit), then go to Start -> Python 3.9 -> IDLE (Python 3.9 64-bit). Whatever your system is say Linux, Apple Mac etc. do follow the similar steps to open the Python IDLE. Here is the snapshot:
And here is the snapshot of the Windows IDLE Shell 3.9.6. The windows opened after clicking on IDLE (Python 3.9 64-bit) as told above:
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 the Python Shell windows opened, therefore navigate to or click on FILE -> NEW FILE as shown in the snapshot given below:
A new windows opened after navigating as told above. Now type the following code in that window:
print("Hey!, Welcome to codescracker.com")
like shown in the snapshot given below:
As the simplest Python code is written, now save the code by navigating File -> Save As... like shown in the snapshot given below:
Here is the window opened after navigating as told above:
As shown in the above snapshot, type the name of program say codescracker.py and press
ENTER key. Now your Python
source code is saved. Follow the step no.4 given below.
Python IDLE Setup - Step No.4
Since the Python source code is saved, therefore this is the time to execute or run the program. To do this, either navigate to Run - > Run Module (F5) or just press F5 key to run the program. Here is the output produced:
Let's create another Python code and execute 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 F5 key to run it. Here is the output produced:
Since this is just a demo of how a Python program can be executed. Therefore don't worry about the code. You'll get to learn about its working step by step later on.
Now you're able to execute a 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, a Python software is needed.
Execute Python Program using PyCharm
Download PyCharm from internet and install it. After installing, navigate to Start -> JetBrains -> PyCharm Community Edition. Here is the snapshot of the initial windows of PyCharm:
Click on New Project. Here is the new opened windows:
As indicated above, type codescracker in the Location field and click on the Create button. Again a new windows gets opened. Therefore navigate to Project -> codescracker -> Right Mouse Click -> New -> Python File as shown in the snapshot given below:
A new small windows gets opened like shown in the snapshot given below:
As shown above, type codescracker.py as name and press
ENTER key. Now the file gets created. Now type your Python
code again. Here is the snapshot after typing the Python code:
Now to run this code, either navigate to Run -> Run -> ENTER Key or Press Shift + F10 key and then
ENTER Key. From next time, the program written in same file need not require to press
ENTER key after pressing
Shift + F10 key to run the program. That's it
« Previous Tutorial Next Tutorial »
Follow/Like Us on Facebook
Subscribe Us on YouTube