- Python Basics
- Python Tutorial
- Python Applications
- Python Versions
- Python environment setup
- Python Basic Syntax
- Python end (end=)
- Python sep (sep=)
- Python Comments
- Python Identifiers
- Python Variables
- Python Operators
- Python Ternary Operator
- Python Operator Precedence
- Python Control and Decision
- Python Decision Making
- Python if elif else
- Python Loops
- Python for Loop
- Python while Loop
- Python break Statement
- Python continue Statement
- Python pass Statement
- Python break vs. continue
- Python pass vs. continue
- Python Built-in Types
- Python Data Types
- Python Lists
- Python Tuples
- Python Sets
- Python frozenset
- Python Dictionary
- List vs. Tuple vs. Dict vs. Set
- Python Numbers
- Python Strings
- Python bytes
- Python bytearray
- Python memoryview
- Python Misc Topics
- Python Functions
- Python Variable Scope
- Python Enumeration
- Python import Statement
- Python Modules
- Python operator Module
- Python os Module
- Python Date and Time
- Python Exception Handling
- Python File Handling
- Python Advanced
- Python Classes and Objects
- Python @classmethod Decorator
- Python @staticmethod Decorator
- Python Class vs. Static Method
- Python @property Decorator
- Python Keywords
- Python Keywords
- Python and
- Python or
- Python not
- Python True
- Python False
- Python None
- Python in
- Python is
- Python as
- Python with
- Python yield
- Python return
- Python del
- Python from
- Python lambda
- Python assert
- Python Built-in Functions
- Python All Built-in Functions
- Python print() Function
- Python input() Function
- Python int() Function
- Python len() Function
- Python range() Function
- Python str() Function
- Python ord() Function
- Python chr() Function
- Python read()
- Python write()
- Python open()
- Python Examples
- Python Examples
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:
- Python IDLE can be used to directly execute a Python program.
- 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:
- It is free.
- It is lightweight.
- Best suited for Python
- offers much more functionality for Python programming.
- It makes development easier and more productive.
- offers many built-in developer tools.
- And the most important feature is that it provides intelligent coding assistance.
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:
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:
As indicated above, click on the Download button from the main navigation to open the download page that looks like this:
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:
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:
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:
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:
As the simplest Python code is written, now save the code by navigating File -> Save As..., as shown in the snapshot given below:
Here is the window opened after navigating as described above:
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:
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:
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:
Click on "New Project." Here is the newly opened window:
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:
A new small window gets opened, as shown in the snapshot below:
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:
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.
« Previous Tutorial Next Tutorial »