IronPython

From Wildsong
Revision as of 16:28, 9 June 2011 by Brian Wilson (talk | contribs)
Jump to navigationJump to search

Okay, so I want to write an installer for a .Net 3.5 program. I want to write it in Python because I think Python is a great language.

I tried valiantly to get py2exe to build me a Python 2.6 executable using wxPython. I followed all the instructions in the py2exe 5.2 section, I tried many other variations, I failed. Can't load msvcp90.dll.

Maybe if I use IronPython, I think I can get things going. Turns out this is true, I can!

IronPython 2.6.1 will run on .Net 2.0 SP1, and that means it's good on Windows XP or Windows 7. I don't care about Windows Vista. (No one does!)

I installed both the 2.6.1 for .Net 2 and the 2.7 versions of IronPython. (The 2.7 version requires .Net 4.0. Later for that!)

The IronPython tutorial uses the text driven console. 2.7 supports a Visual Studio 2010 development environment. I wish Komodo supported IronPython.

I think I will develop in VS2010 with 2.7 and then backport to 2.6

If you install VS2010 and then install IronPython 2.7, it will install the VS support. Ignore the docs that say to click on the VSIX file, there isn't one.

Sample app =

import clr
clr.AddReference('System.Windows.Forms')
from System.Windows.Forms import *

class MyForm(Form):
    def __init__(self):
         self.quit_button = Button()
         self.quit_button.Text = 'Quit'
         self.Controls.Add(self.quit_button)
 
def OnClick(*args):
   form.Close()
   return

form.Text = "My beloved sample app"
form.quit_button.Click += OnClick
form.Show()

Application.Run(form)

Running it from a command line

ipyw.exe Program.py

But does it run in .Net 2 environment? Well, sure it does!

But do I have to preinstall IronPython from the MSI or can I just run ipyw? NO. I don't I did the MSI install and then copied the file tree into a convenient place. I was able to run it no problems.