How to set environment variable using virtualenv?

I am trying to configure an external / lib program written in python - on debian squeeze.

The error that I get when I try to run it so that the "environment variable is not set" is the exception that the developer throws. Therefore, I think I should define it, but where?

  • I thought virtualenv and path were the same, so I wrote pth loaded at startup. He solved the error, but not all.
  • I read the use of export in ~/.bashrc , but I'm not sure if it is readable in virtualenv, and I do not want this export to be read even if I do not use this virtualenv.
  • I also read to use export in virtualenv/bin/activate , but it does not work correctly.

I am trying to install Opus and Urbansim .

Here is what I get on startup:

 (opus-env) touki@touki :~/Projects/opus-env$ ./src/opus_gui/opus.py Traceback (most recent call last): File "./src/opus_gui/opus.py", line 14, in <module> from opus_gui.main.controllers.opus_gui_configuration import OpusGuiConfiguration File "/home/touki/Projects/opus-test/src/opus_gui/main/controllers/opus_gui_configuration.py", line 12, in <module> from opus_core import paths File "/home/touki/Projects/opus-test/src/opus_core/paths.py", line 44, in <module> OPUS_HOME = _safe_getenv('OPUS_HOME', _get_default_opus_home) File "/home/touki/Projects/opus-test/src/opus_core/paths.py", line 33, in _safe_getenv return os.environ[key] if key in os.environ else default_func() File "/home/touki/Projects/opus-test/src/opus_core/paths.py", line 36, in _get_default_opus_home raise Exception('OPUS_HOME environment variable must be set.') Exception: OPUS_HOME environment variable must be set. 

NB: I was looking for autoenv to combine virtualenvwrapper seems to give an answer, but I would rather not use external programs.

+4
source share
2 answers

if you add to opus-env/bin/activate

 OPUS_HOME="some value" export OPUS_HOME 

It should work (your decision 3). Of course, it will not apply to currently running processes.

Try to exit the current virtualenv shell session, start a new shell session, activate the changed virtualenv in this new session. Before starting the program, check the environment:

 env | grep OPUS_HOME 
+7
source

Hmm, maybe use:

 ~virutalenv/bin/python opus.py 
0
source

Source: https://habr.com/ru/post/1444092/


All Articles