There are a couple of suggestions on this forum:
- If the variable is static for a given kernel you could set it in the kernel spec: How can I pass environment variabel PYTHONPATH to jupyter notebook? - #2 by kevin-bates
- If you the variable is more dynamic you could use a wrapper script: Unable to reliably use single JypyterLab server with multiple conda environments - #3 by jonburdo