Blender seems to have rearranged how you install additional python modules in 4.2 and some old code I was using no longer seems to work.
This was working in 4.1:
import subprocess
import os
import sys
python = os.path.abspath(sys.executable)
subprocess.call([python, "-m", "pip", "install", "gruut"])
print("Done")
This code still works in the sense that it will install the library, but the library is still inaccessible. If I type import gruut in the script window, it prints an error that the module cannot be found. (Strangely, if I run the command help('modules'), it is printed to the console as being present and after that the import gruut command starts working).
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
ModuleNotFoundError: No module named 'gruut'
The same is true for other modules I want to install. Have things changed in 4.2? What is the right way to install modules in Blender now?
I am running into the same issue, or at least similar.
My assumption is, we are now supposed to use Python Wheels through Extensions. Meaning, whenever you want to use another module, you have to create an Extension. However, I have not tested this yet. If someone knows, that would be great.
Well you are in luck as I have an extension that I use for coding 
Make sure to renable the extension after installing module
So is my assumption correct that modules now have to be installed with wheels inside of extensions?
If that is the case, I prefer to actually do it like that, rather than relying on the previous HACK.
Nevertheless, thanks for the link!
This method is much better and practical then installing modules directly into blender python . It is much easier to implement and use threading for installing modules so no blender freezing.
Anyway I made this tool sometime ago but did not occur to me that it can be useful for other people . It is pretty bare bone . I might update it and seams like a good idea.
I have been experimenting a bit and it seems that Blender 4.2 simply doesn’t like pyexr. I created a dummy extension, containing the pyexr wheels and it didn’t work either. Exact same issue as when I installed it with the pip hack.
Yes, there are some modules that simply does not work with blender like pygame. It is mainly because there are some default python libraries that are not present or have different version in the python that comes with blender. If you really want to use these . You can try deleting the python interpeter that comes with blender . Then it will fall back to python that is installed on your system . I do not know if it works or not .
I am looking for a simple and reliable solution, with as little work as possible. What I described worked in 4.1, but it is broken in 4.2. Because it is an external module and because there are plenty of changes in Blender, including Python, due to the introduction of Extensions, I just wanted to make sure I am not missing something obvious.