2

This moment, I am using pyenv + venv to manage Python versions and specific libraries. My project layout looks like this:

  1. dir1
    • subdir11
    • subdir12
    • subdir13
  2. dir2
    • subdir21
    • subdir22
    • subdir23

My goal is, once venv is activated dir1 and dir2 to be inside sys.path. Basically, I solve this task but I really do not like solution. I added custom PYTHONPATH inside venv under bin/activate file and everything works fine. This is not so flexible from deployment point of view. Does venv provide some hooks for this ? For example: set customer environment variables once venv is activated or run some function or something like this. I do not like idea, to modify bin/activate file on every machine.
P.S I know about packaging stuff and setuptools, but for this project I can not use it.

Any ideas ?

Thanks !

1 Answers1

2

Another possibility (which is usually what I use and avoids going into you venv source code) :

Create an activate.sh script where you export path to your modules AND activate venv ie :

source venv/bin/activate
export PYTHONPATH=$PYTHONPATH:$(pwd)

then you can just do source activate.sh instead of source venv/bin/activate and you will have both actions at once.

Luis Blanche
  • 557
  • 9
  • 18
  • 1
    Yes, but it means `venv` does not provide some kind of `hooks`. Anyway, thanks for answer Luis. I just can vote up your answer. – pyargskwargs Mar 09 '21 at 18:02