I am developing an addon that uses some modules that are not installed in Python in Blender by default such as cv2 and PIL. On my pc the script can run due to the fact I installed both modules in Python, however, when installing the addon on other pcs, blender raises the ModuleNotFoundError because such modules are not loaded into that specific Python.
How could I handle this situation? I have been trying to figure out how could I install the modules before the program execution. Yet I have not been able to solve it.
The code to this extent is structured like this:
import bpy
import os
from PIL import Image
import cv2 as cv
bl_info = {
"name": "New Object",
"author": "Your Name Here",
"version": (1, 0),
"category": "Add Mesh"
)
class MESH_OT_pinguin(bpy.types.Operator):
...
def execute(self, context):
...
#Here goes the script that uses such libraries
def menu_func(self, context):
self.layout.operator(MESH_OT_pinguin.bl_idname, icon='MESH_CUBE')
def register():
bpy.utils.register_class(MESH_OT_pinguin)
bpy.types.VIEW3D_MT_mesh_add.append(menu_func)
def unregister():
bpy.utils.unregister_class(MESH_OT_pinguin)
bpy.types.VIEW3D_MT_mesh_add.remove(menu_func)
if name == "main":
register()

pip install? can u not run pip install while installing your addon? – Harry McKenzie Apr 20 '23 at 16:24try: from PIL import Image # pip install Pillow except: subprocess.check_call([sys.executable, '-m', 'pip', 'install',"Pillow"]) from PIL import Image– George Apr 28 '23 at 14:44