|
|
| |
|
|
|
|
|
|
Initializes the Python runtime, including redirecting sys.stdout
and sys.stderr and setting up the virtual environment.
|
|
|
|
| |
|
[C#]
bool AutoInitializeRuntime(PythonScope scope, string
venvPath = null)
ArgumentNullException:
Thrown when scope is null.
ArgumentException: Thrown
when the environment of scope is different from the Python
environment of this PythonRuntime.
ObjectDisposedException:
Thrown when this PythonRuntime has
been disposed of.
|
|
|
|
| |
|
| |
|
Initializes the Python runtime, including redirecting sys.stdout
and sys.stderr and setting up the virtual environment.
If initialization is performed,
PythonEnvironment.RuntimeIsInitialized is set to
AutoInitialized.
|
|
|
|
| |
|
To use a virtual environment, you need to initialize the Python
engine with PythonOptions.SetNoSiteFlag
true and to provide the path to the directory of the virtual
environment. This example shows how you might do this.
string venvPath = @"C:\MyVenv";
var env = PythonEnvironment.Current;
var options = new PythonOptions { SetNoSiteFlag = !string.IsNullOrEmpty(venvPath) };
options.Initialize(env, null);
using var rt = env.GetRuntime();
using var scope = rt.CreateScope();
rt.StdOutWriter = Console.Out;
rt.StdErrWriter = Console.Error;
rt.AutoInitializeRuntime(scope, venvPath);
// ... do work
|
|
|
|