How to Configure OBS to Run Python Scripts
How to add and run Python scripts in OBS? How to set the Python installation path for OBSDemonstration (Traditional Chinese) YouTube
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 doesn’t seem to use the environment variable PATH
to locate Python, so if you want Python to start correctly, you need to specify the location of the Python installation for OBS.
You can open the Scripts Window through OBS’s 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. You can choose to install a different version of Python and respecify the Python installation path in the Python Settings Tab.
After you specify a new Python installation path for OBS, 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.
# 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 in OBS
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 Python’s Module Search Path by OBS, so you can import it directly using the module name.
The script_log function of the OBS obspython module
The script_log
function of the obspython
module 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 OBS 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 Python 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
Tutorial Videos
How to add and run Python scripts in OBS? How to set the Python installation path for OBS·YouTube