How to add a environment variable to Google AI Notebook?

Viewed 423

I would like to include an environment variable on a Google VM which is running a JupyterLab notebook - this variable needs to be present before the notebook is started.

So setting it in the terminal or in the notebook does not work.

I have also tried to modify the bashrc with no luck.

2 Answers

In order to have an environment variable set up on you Compute Engine instance from boot you might be interested in checking startup scripts.

Startup scripts are automated tasks that are performed when your instance boots up. To set them it can be done when creating the instance under the automation section; if the instance is already created accessing your instance details in the compute engine console and under custom metadata clicking on Add item.

Steps to create startup scripts can be found here and here.

If you mean google Colab, one solution is using python, for example:

import os
os.environ["BASE_DIR"]="/content/drive/MyDrive/"
Related