|
|
| |
|
|
|
|
|
|
Initializes the Python runtime, including redirecting sys.
|
|
|
|
| |
|
[C#]
bool AutoInitializeRuntime(PythonScope scope, string
venvPath)
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.
|
|
|
|
| |
| Name
|
Description
|
| scope |
The Python scope for running initialization code. |
| venvPath |
The directory path for a Python virtual environment if not
null/empty. It is ignored if is not . It should be null/empty for
all calls except (possibly) for the first call. Please see for
details. |
| return |
Whether initialization is performed. Initialization is
performed if is Uninitialized or AutoInitialized. |
|
|
|
|
| |
|
Initializes the Python runtime, including redirecting sys.stdout
and sys.stderr<
and setting up the virtual environment.
If initialization is performed, PythonEnv.RuntimeIsInitialized
is set to RuntimeInitializationState.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 = true };
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
|
|
|
|