I can create Python scripts and dynamically run them through Visual Studio / .NET 4.0 as follows:
# 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")
and then in the .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 do not contain all the standard modules, so I need to do
import sys sys.path.append(r'C:\Program Files (x86)\IronPython 2.7.1\Lib')
so that I can run the next 4 lines.
Is there any way to avoid this?
I am going to publish the application, and I do not want to rely on the fact that the file path is the same on all machines!
source share