The module was installing itself in the appdata folder.
Thanks to the last reply I managed to piece it back together.
I forced installing in local environment by replacing the last line with
subprocess.call([str(py_exec),"-m", "pip", "install", f"--target={str(py_exec)[:-14]}" + "lib", "your_module"])
By the way the console kept bugging me to replace bpy.app.binary_path_python
by sys.executable
so I changed that too.
I didn’t need to launch in administrator mode (Windows).
Full script :
import subprocess
import sys
import os
from pathlib import Path
py_exec = str(sys.executable)
# Get lib directory
lib = os.path.join(Path(py_exec).parent.parent, "lib")
# Ensure pip is installed
subprocess.call([py_exec, "-m", "ensurepip", "--user" ])
# Update pip (not mandatory)
subprocess.call([py_exec, "-m", "pip", "install", "--upgrade", "pip" ])
# Install package
subprocess.call([py_exec,"-m", "pip", "install", f"--target={str(lib)}", "your_package"]