URLhttps://learnscript.net/en/obs-python-scripting/setup/
    Copy LinkGo to Instructions  Example

    How to Configure OBS to Run Python Scripts

    Beatme CodeBY-NC-ND
    6:00 read·782 words· modified

    OBS Studio

    OBS is a free and open-source live streaming software that supports users to develop plugins or run scripts written in Python to expand functionality.

    Install Python

    Since the installation package provided by OBS does not come with Python, your operating system needs to have a certain version of Python, which is one of the prerequisites for running Python scripts in OBS.

    Python Installation

    For more information on how to install Python, you can check out the article How to Install Python on UNIX/Linux/Windows/macOS of Python Tutorial.

    Set the Python Installation Path for OBS

    OBS does not seem to use the environment variable PATH to locate Python, and you need to specify its installation location for OBS if you want Python to start correctly.

    You can open the Scripts Window through the menu item Tools | Scripts, and then switch to the Python Settings Tab in order to select the installation path where Python is located, from which OBS will load Python and display its version information.

    OBS may not support the latest or outdated versions of Python

    OBS may not support the latest or outdated versions of Python, in which case a message like “Python not currently loaded” will appear in the Python Settings Tab. At this point, you can choose to install another version and respecify the installation path in the Python Settings tab.

    After you specify a new installation path, OBS may prompt you to restart to load Python from the new path.

    Write Python Scripts for OBS

    Next, let’s prepare a file named hello_world.py and write a simple piece of code in it, which will display the Python Module Search Path in the Script Log Window of OBS.

    hello_world.py
    # Import the obspython module
    import obspython as obs
    
    # The Python Module Search Path will be displayed in the Script Log Window import sys obs.script_log(obs.LOG_INFO, str(sys.path))

    The obspython module

    OBS provides an important Python module, obspython, which is used to invoke various functions in OBS, or to get and set certain states of OBS. The directory where this module is located will be added to the Module Search Path, so you can import it directly using the module name.

    The script_log function of the obspython module

    The script_log function is used to output messages to the Script Log Window, and can be used to assist in debugging or display prompt information.

    Configure VSCode

    Since OBS itself does not provide script editing capabilities, this guide will use VSCode to write Python code. You can get the information from the article How to Configure VSCode to Write and Run Python Code of Python Tutorial.

    Add Python Scripts to OBS

    In the Scripts Tab of the Scripts Window, click the Add Scripts Button to add a Python script file, and the added file will appear in the Loaded Scripts Listbox. Here, we need to add the file hello_world.py that we wrote earlier.

    Run Python Scripts in OBS

    Once you have successfully added Python scripts to OBS, they will run automatically, so nothing special is required.

    Here, we open the Script Log Window via the Script Log Button in the Scripts Tab, which shows the Module Search Path, indicating that the file hello_world.py has indeed been run.

    # Output in Windows
    [hello_world.py] ['\\data\\obs-scripting\\64bit',]

    Reload Python Scripts in OBS

    Select the Python script you want to reload in the Loaded Scripts Listbox, and then click the Reload Scripts Button to reload the script, which means, of course, re-running.

    Remove Python Scripts in OBS

    Select the Python script you want to remove from the Loaded Scripts Listbox, and then click the Remove Scripts Button to remove the script.

    Source Code

    hello_world.py·codebeatme/obs-python-scripting·GitHub

    Tutorial Videos

    BS 新增、執行 Python 腳本,設定 Python 安裝路徑|Python 串流開發教學·YouTube