How to enforce a mesa driver override in a python script?

I need to start MATLAB with the parameters “env MESA_LOADER_DRIVER_OVERRIDE=i965”. I could edit my .desktop file and also add an alias in .bashrc. Now I need to set this environment override in a python script. I have tried

os.environ['env MESA_LOADER_DRIVER_OVERRIDE=i965']



Unfortunately both throw an error. And well sure - both of them are bash commands. I probably need to set something like a .pythonrc up.

If you want env vars from the system you need
import os
To set them ex:
You can print them with ex:

Tried that and I am getting this error

Traceback (most recent call last):                                                                                                                       
 File "~/.config/nvim/plugged/vim-matlab/ftplugin/matlab/../../scripts/", line 28, in <module>                           
 os.environ[MESA_LOADER_DRIVER_OVERRIDE]=i965                                                                                                          │
 NameError: name 'i965' is not defined                                                                                                                     

 [Process exited 1]                                                                                                                                                           

Since it already imports os, do I maybe have to set this environment variable in my .xintrc? The problem is that I only need this driver for MATLAB. I don’t want to set it as a global driver. An alias would work better, but that probably doesn’t get piped into python, does it?

Solution was:

env = os.environ.copy()

self.proc = Popen(["matlab", "-nosplash", "-nodesktop"], stdin=PIPE,
                          close_fds=True, preexec_fn=os.setsid, env=env)

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.