OPENAI_API_KEY in JupyterLab

Hi all, I have JupyterLab on my MAC.

I have configured my OpenAI API key for all projects via terminal and I can verify the configuration by typing echo $OPENAI_API_KEY in the terminal and it shows my API key correctly or I use printenv and it shows my API key correctly.

My API KEY appear here
open ./.zshrc

So far so good.

Now, I use on a cell
%env
My API KEY doesn’t appear, why? How can I get my OPENAI_API_KEY environment variable in JupiterLAb?

I import environment vars this way and it works as expected:

import os
api_key = os.getenv('OPENAI_API_KEY')

Thanks @spookster

I execute
import os
api_key = os.getenv(‘OPENAI_API_KEY’). I don’t know why it’s not working for me

The return is
None (Not found)

I execute
os.environ. (it doesn’t appear the OPENAI_API_KEY environment variable )

I don’t understand what it is happening

do you use a virtual environment?

I don’t have idea

I did this to check it
import sys
print(sys.executable)

and return path, what place python is run
…/Library/jupyterlab-desktop/jlab_server/bin/python

In this case, when I run …/Library/jupyterlab-desktop/jlab_server/bin/python (3.8.18) by Terminal, I did this
'>>> import os
'>>> api_key = os.getenv(‘OPENAI_API_KEY’)
'>>> print(api_key)
sk-… (The API_KEY is showed)

On my Notebook Jupyter I did this:
from platform import python_version
print(python_version())
and returned
3.8.18

Somehow from JupyterLab it doesn’t allow me to access to environment variable OPENAI_API_KEY
My version in langchain is 0.0.350

By the way, I have just installed Anaconda Navigator (I don’t know if can be useful)