Ironpython is python under .NET environment and it is made to access all the .NET classes and libraries keeping all the features of original distribution intact. If you’re programming python under windows environment then it is better to get ironpython instead of python’s official distribution. Why ? Because once you pass the basic level of python programming then surely your interests will be to use python either for desktop app or web app. In such case you can benefit a lot from ironpython distribution than official distribution under windows environment. In this article you’ll learn how to program your first ironpython hello world app.
Download Ironython from official ironpython source. Official MSI installer will not only install the command prompt but also extension for your visual studio setup. If you don’t have visual studio installed on your computer then it is better to get sharpdevelop IDE for working with ironpython or other .NET programming languages. Though sharpdevelop version will not be up to date for ironpython, you can still use it for most of your task and then later port your code to updated version.
Setting Environment Variables
It’s not possible to get the ironpython in command line to use ipy on almost any drive. In such a case you need to add the entry to environment variables on your computer. This procedure applies to windows XP and higher operating systems.
1. Right click on My computer Icon > Properties.
2. This will open up a window with mutiple tabs. Click on Advanced tab and then click on ‘Environmen variable’ button at the bottom of window.
3. In new window you’ll see environment variable options, go to System variables and click on value path to select it.
4. Now click on edit button to edit the variable ‘Path’.
5. You have to paste the path for ‘ipy.exe’ in your ironpython installation in this text field. End the path with coma or semi-colon which ever applies there in the text box.
6. Save the path with ok button and then exit from environment variables window.
By following above procedure you can easily get ‘ipy.exe’ working on any drive in command prompt.
Ironpython- Hello World on command prompt
Now that you can open ipy.exe on any drive you should start writing your python programs. So let’s start with simple hello world program.
Type the following –
This will open up python interpreter on your command line. Now type the following code –
print 'hello world';
This will return ‘hello world’ on your command prompt.
Now let’s create a simple window based app that prints ‘hello world’ on it.
from System.Windows.Forms import Application, Form, Label
form = Form(Text=”Hello World Form”)
label = Label(Text=”Hello World!”)
Above code will produce windows app which you can close, maximize or minimize. Make sure you type code properly in order to avoid the errors. Hope this tutorial helps you to create simple python application.