[Python.NET] Setting PYTHONPATH from code

Oleksii Bidiuk oleksii.bidiuk at gmail.com
Thu Feb 10 13:20:54 CET 2011


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, '" + <variable_with_path> +
"')");
IntPtr pythonLock = AcquireLock();
RunSimpleString(script);
ReleaseLock(pythonLock);

Does this help?

2011/2/10 Sharon Rozenblum <Sharon.Rozenblum at sandisk.com>

>  Hi!
>
>
>
> Can someone tell me how to set PYTHONPATH variable in code when working
> with Python.Runtime.dll without changing the value in the system variables
> before.
>
>
>
> Thanks
>
>
>
> SHARON
>
>
>
> ------------------------------
> PLEASE NOTE: The information contained in this electronic mail message is
> intended only for the use of the designated recipient(s) named above. If the
> reader of this message is not the intended recipient, you are hereby
> notified that you have received this message in error and that any review,
> dissemination, distribution, or copying of this message is strictly
> prohibited. If you have received this communication in error, please notify
> the sender by telephone or e-mail (as shown above) immediately and destroy
> any and all copies of this message in your possession (whether hard copies
> or electronically stored copies).
>
>
> _________________________________________________
> Python.NET mailing list - PythonDotNet at python.org
> http://mail.python.org/mailman/listinfo/pythondotnet
>



-- 
oleksii
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythondotnet/attachments/20110210/453dc39b/attachment.html>


More information about the PythonDotNet mailing list