0

[Background]

I am used to use xx.py and defining a .env file in python project in Pycharm, and by doing

import os
os.environ['abc']

I will get the 'abc' variable defined in .env file.

[Question]

Now I need to work with sagemake studio, what is the best practice to manage env var with sagemake?

I tried to create a .env file, but got a rename error. Does it mean using .env is not a good try in sagemaker?

Rename Error
Cannot rename file or directory '/xx/untitled.txt'
Mapotofu
  • 268
  • 2
  • 4
  • 15

1 Answers1

0

This worked for me. Steps followed:

  1. Create a text file. E.g. EnvVars.txt

  2. Added two lines:

  • ENTRY1=VALUE1
  • FOO=BAR
  1. In the SageMaker studio notebook cell added the following:
  • from dotenv import load_dotenv
  • load_dotenv("EnvVars.txt")

PS: Make sure you do pip install python-dotenv beforehand via terminal or another notebook cell.

  1. print(os.getenv('ENTRY1')) # This gives VALUE1
Shanks
  • 11
  • 3