Class PythonRunner
This class encapsulates the Unity Editor API support for Python.
Inheritance
Namespace: UnityEditor.Scripting.Python
Syntax
public static class PythonRunner : object
Properties
IsInitialized
Verify whether Python has been initialized yet.
Normally you'd simply call EnsureInitialized without checking. This access is principally useful when shutting down.
Declaration
public static bool IsInitialized { get; }
Property Value
Type | Description |
---|---|
Boolean |
PythonInterpreter
The full path to the Python interpreter.
Accessing this initializes Python if it hasn't been already.
Declaration
public static string PythonInterpreter { get; }
Property Value
Type | Description |
---|---|
String | A string representing the full path to the Python executable. |
PythonVersion
The version of the Python interpreter.
Accessing this initializes Python if it hasn't been already.
Declaration
public static string PythonVersion { get; }
Property Value
Type | Description |
---|---|
String | A string representing the version. |
Methods
EnsureInitialized()
Ensures the Python API is initialized.
Safe to call frequently.
Throws if there's an installation error.
Declaration
public static void EnsureInitialized()
RunFile(String, String)
Runs a Python script in the Unity process.
Declaration
public static void RunFile(string pythonFileToExecute, string scopeName = null)
Parameters
Type | Name | Description |
---|---|---|
String | pythonFileToExecute | The script to execute. |
String | scopeName | Value to write to Python special variable |
RunString(String, String)
Runs Python code in the Unity process.
Declaration
public static void RunString(string pythonCodeToExecute, string scopeName = null)
Parameters
Type | Name | Description |
---|---|---|
String | pythonCodeToExecute | The code to execute. |
String | scopeName | Value to write to Python special variable |