docs.unity3d.com
    Show / Hide Table of Contents

    Class PythonRunner

    This class encapsulates the Unity Editor API support for Python.

    Inheritance
    System.Object
    PythonRunner
    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 __name__

    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 __name__

    In This Article
    • Properties
      • IsInitialized
      • PythonInterpreter
      • PythonVersion
    • Methods
      • EnsureInitialized()
      • RunFile(String, String)
      • RunString(String, String)
    Back to top
    Terms of use
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023