Hi all,
I am trying to make calls to methods in a python script from within my C# form app. I have installed IronPython 2.7, and I am using visual studio 2010. (FYI, I tried a simple version of this with no imports from my script, and it worked, I was able to make calls to the method)
The application compiles just fine, however when I try to run it, I get a IronPyhton runtime error like this: No module named optparse. This is a module I am importing from my python script file. It appears that there is a missing python dll somewhere, or the wrong dlls, because if I comment out the import optparse line, then the error moves to the next module which is the "os" module. If I comment out that line, the error moves to the next import, and so on,,,, I even tried re-arranging the order of the imported modules.
I have added references in my VS project to the ipy, ironpython, ironpython.module, and several Microsoft suggested DLLs, like Microsoft.Dynamic.
To no avail. Could there be a path issue? Could I be referencing the wrong DLLs?
I found these DLLs under the C:\WINDOWS\Microsoft.NET\assembly\GAC_MSIL
so this is where they are referenced to.
Anybody else have a similar issue like this before?
Here is what I am including in my form file:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using IronPython.Hosting;
using IronPython.Modules;
using IronPython.Runtime;
using System.IO;
Here is the little snippet of code where I implement this,
public Form1()
{
InitializeComponent();
var ipy = Python.CreateRuntime();
try
{
dynamic logfile = ipy.UseFile("logparser.py");
}
catch (FileNotFoundException)<pre>
{
MessageBox.Show("unable to open logparser.py");
}
}
And here are the modules I am importing in my script:
import System
import os
from datetime import datetime, timedelta
import sys
import re
import thread
import time
from optparse import OptionParser