PythonWin is the name of the IDE (Interactive Development Environment) for the Windows extension. It gets installed by default whenever you install Python for windows extension.
Thus, for all the python programs running on the Windows operating system, PythonWin acts as a graphical user interface for running the programs. In addition, it has several features in its environment, which makes debugging and editing python code an easier task.
What is an IDE?
IDE stands for Interactive Development Environment. Since PythonWin is an IDE, it is essential to know first what exactly is an IDE. An IDE is a single software that contains all the features for building applications.
The features contained inside an IDE are code editor, debugger, building tools, and compiler. By using an IDE, we don’t have to configure each tool separately. Thus, enabling us to develop applications at a faster rate.
Apart from PythonWin, python has different IDEs such as PyCharm, Visual Studio Code, Jupyter Notebook, Google Colab, Sublime Text, etc.
To install PythonWin on a windows computer, you need to install ‘Python for Windows Extensions‘ from SourceForge.
The link for the PyWin is : https://sourceforge.net/projects/pywin32/
The SourceForge page would appear something like this:
Select the Get option and select the latest suitable version for your computer. First, you need to ensure that the PythonWin version is compatible with the version of the python software on your computer.
After that, the installation will start right away.
After installing, a window will appear for the PythonWin setup. Submit on Next.
Then, it will ask for the location of the directory in which the Python software is installed. If you have already installed it, it will find the location by default. Again select on Next.
The installation will start.
Now, select Finish.
Now if you will search for PythonWin on the windows start menu, you can see that it has been installed on your local computer.
After installing the software, when you will open the PythonWin application, it would look something like this:
As you can see, the software’s toolbar and menu bar are visible on the top of the screen. The interactive window is where we will type the python commands and run them. The three arrows (>>>) here indicate the command prompt.
Executing a Code
We will try to execute running a print statement in PythonWin. We will print the statement “Programming in PythonWin“. For that, you have to type:
print(“Programming in PythonWin”) next to the ‘>>>’ symbol. The statement will be printed as the output.
Creating a New script
To create a new script, go to the ‘File‘ option present in the toolbar. Then, select the first option – ‘New‘ or you can press the control key + N.
A window will appear. Select ‘Python Script‘ from the given options and select ‘OK.’
A new window titled ‘Script1‘ will appear as the new script.
Let us try to run some code in this new script.
We will try to perform simple addition of two numbers. We will take two numbers ‘a’ and ‘b’ from the user and print their addition.
Now, to execute the code, we will have to first save the script. To save the script, select File from the toolbar. Visit the ‘Save’ option or press the control key + S. A window pops up.
Give the script a name and press the ‘Save‘ button. Here, we have given it the name ‘Script1‘ with the ‘.py‘ extension.
Running the New Script
To run that script, press the ‘Run‘ icon present on the top. A window named ‘Run Script‘ will appear.
The window will mention the location of the script file. It has two other fields: ‘ Arguments‘ and ‘Debugging.’ By default, the debugging field will be set to ‘No debugging.’ Select ‘OK.’
Now, since the above code accepts input from the user, it will first ask for the user to Enter first number. Enter an input number and select OK.
Then, enter the second number and select OK.
In the interactive window, the output will be printed. In this case, the output is
'Their summation is : 15'.
To open a given file, you can either press ‘ctrl + O” or go to ‘File‘ and select ‘Open.’ Now, select the location of the script file from the window pop up and press on ‘Open‘. The script file will open.
Debugging with PythonWin
PythonWin is known for its debugging features which help in writing a code efficiently. Debugging refers to the process of finding and removing errors and bugs from a code.
PythonWin has several debugging tools which help in identifying and resolving errors. Debugging shall execute our code line by line for any error.
PythonWin has a check option that will find any syntax errors if present in the code. At the bottom of the window, it will list the syntax error along with the line in which it occurred.
For example, in the ‘Script1’ program, we will remove one parenthesis from the first input statement. Then, on using the check tool, it will display ‘Syntax Error‘ at the bottom of the window.
The error says 'Invalid Syntax'.
In case of multiple errors, it will show one error at a time, line by line. After typing the missing parenthesis, the error will be resolved. At the bottom, it will show the message that it was successfully able to check the file.
Now, we will see the debugging tools available in PythonWin. From the ‘View‘ option in the toolbar, select tools. There, check on the ‘Debugging‘ option.
You will see an entire toolbar containing debugging tools appears.
‘Watch’ tool: It helps in keeping track of the changes occurring in the variables.
‘Step’ tools: These three tools step through the list by debugging one line at a time.
‘Breakpoint’ tool: Used to set a breakpoint to fulfil a condition.
ArcGIS is a library in python containing a powerful set of tools for analysis and visualization. We can use the PythonWin IDE for ArcGIS.
To use PythonWin on ArcGIS, go to ArcGIS Pro Python’s command prompt. Type the ‘idle’ in the command prompt, and this would load the graphical user interface of the PythonWin idle.
PythonWin is an IDE. IDLE stands for Integrated development and learning environment.
PythonWin is a software development package containing tools such as Debugger, editor, compiler, and building tools.
At the same time, IDLE consists of basic packages and concepts of an IDE. The purpose of IDLE is for learning and education.
That sums up PythonWin. If you have any questions, let us know in the comments below.
Till then, Happy Learning!