1

I've been using ipython notebook and there are 2 information (SNOW_USER and PASSWORD) that I need to pass so I can connect to the database. I don't want to expose it for security reasons.

I tried to set as ENV VAR (environmental variables) saving it on my .bash_profile and also on .profile using export SNOW_USER='abc' but it doesn't seem ipython can find it.

import os
print os.environ['SNOW_USER']

I also tried:

%env

But the variables are not showing there either.

Any thoughts on how to do it?

lizzie
  • 606
  • 6
  • 15

1 Answers1

1

Try to create a file .env somewhere with in it :

export SNOW_USER="snow_user"
export PASSWORD="password"

and then source it :

source .env

Or just source you bash_profile file :

source ~/.bash_profile
Till
  • 4,183
  • 3
  • 16
  • 18
  • @PadraicCunningham I haven't tried creating `.env`. It worked out. I'm not sure why the `bash_profile` didn't work. – lizzie Apr 06 '16 at 20:15
  • @lizzie, I thought you added to `~/.bash_profille` as per your question and comment? – Padraic Cunningham Apr 06 '16 at 20:16
  • @PadraicCunningham I did add to my bash_profile. What I didn't have was the `.env` file. – lizzie Apr 06 '16 at 20:18
  • @lizzie the `.env` or the `bash_profile` work the same. You just have to source it somehow. But usually it is good to have a `.env` at the root of your project. – Till Apr 06 '16 at 20:20
  • @Till Great to know! – lizzie Apr 06 '16 at 20:20
  • @lizzie, you must not have actually logged out, whatever is in `.profile` would have been executed on login and when you restarted a shell your .bash_profile would have run so there is no reason I know of that .env would work when the others didn't unless of course you did not do what I asked in my original comment – Padraic Cunningham Apr 06 '16 at 20:22
  • @lizzie ... are you really using `bash`? My linux mint uses `dash` and `dash` uses .profile not .bash_profile. `ls -l /bin/sh` should tell you. – tdelaney Apr 06 '16 at 20:37
  • @tdelaney the output from `ls -l /bin/sh` says wheel. I'm using zshell AFAIK. – lizzie Apr 06 '16 at 20:40
  • There is a link about loading `.bash_profile` with `zsh` : http://stackoverflow.com/questions/23233603/how-to-load-bash-profile-when-entering-bash-from-within-zsh – Till Apr 06 '16 at 20:45