Hi!
Trying to do as you said:
string script = "import sys\nsys.path.insert(0, '" + modulePath + "')";
IntPtr pythonLock = PythonEngine.AcquireLock();
PythonEngine.RunSimpleString(script);
PythonEngine.ReleaseLock(pythonLock);
And then:
IntPtr gs = PythonEngine.AcquireLock();
pyportal = PythonEngine.ImportModule(moduleName);
if (pyportal == null)
{
…
}
…
I got Null value from the ImportModule.
When setting the PYTHONPATH manually in the system variables with the “modulePath” and opening the VS is works.
Any idea?
Thanks,
SAHRON
From: Oleksii Bidiuk [mailto:oleksii.bidiuk@gmail.com]
Sent: Thursday, February 10, 2011 2:21 PM
To: Sharon Rozenblum
Cc: pythondotnet@python.org
Subject: Re: [Python.NET] Setting PYTHONPATH from code
Hi Sharon,
What do you want to achieve with this? If you want to provide path for loading your own modules you can change the sys.path value by e.g. running a 'initialization' script with
import sys
sys.path.insert(0, 'your/own/path')
You can build up the script above in C# by inserting the path you need and then performing e.g. RunSimpleString(<script>) like
string script = "import sys\nsys.path.insert(0, '" +