I am able to create Python scripts and dynamically run them via Visual Studio / .NET 4.0 like this:
# testScript.py file:
import sys
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7.1\Lib')
import os
os.environ['HTTP_PROXY'] = "127.0.0.1:8888"
import urllib2
response = urllib2.urlopen("http://www.google.com")
then in a .NET 4.0 WinForms project:
ScriptEngine engine = Python.CreateEngine();
ScriptSource script = engine.CreateScriptSourceFromFile("testScript.py");
ScriptScope scope = engine.CreateScope();
script.Execute(scope);
However, the IronPython DLLs that I import don't contain all the standard modules and so I have to do the
import sys
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7.1\Lib')
step so that I can run the next 4 lines.
Is there some way I can avoid this?
I'm going to be publishing the application and I don't want to have to rely on the file path being the same on everyone's machine!