13

I'm using venv (used pyvenv to create the environment) and would like to set up environment variables here, but postactivate looks like a virtualenv thing. Can this be done with venv?

StringsOnFire
  • 2,616
  • 5
  • 27
  • 48

2 Answers2

11

venv has the activate script which you can modify to add your environment variables.

I would add the variables at the bottom, making a nice comment block to clearly separate the core functionality and my custom variables.

masnun
  • 10,986
  • 4
  • 37
  • 48
0

Put your setup config in [your_virtualenv_dir]/bin/postactivate and your teardown config in [your_virtualenv_dir]/bin/predeactivate.

e.g. in postactivate:

YOUR_ENV_VAR="hello world!"

e.g. in predeactivate:

unset YOUR_ENV_VAR
n_moen
  • 381
  • 2
  • 9