7

I'm trying to set up an external program / lib written in python - on debian squeeze.

The error I get when I try to launch it that the "environment variable is not set" - it's an exception throw by the developer. So I guess, I have to define it, but where ?

  1. I've thought virtualenv and path were the same, so I've written a .pth loaded at the launch. It solved some mistake but not all.
  2. I've read use export in ~/.bashrc but I'm not sure it is read in a virtualenv, and I don't want those export be read even when I don't use this virtualenv.
  3. I've read too to use export in virtualenv/bin/activate, but it doesn't seem to work correctly.

I'm trying to install Opus and Urbansim.

Here is what I get when launching:

(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've searched, autoenv combine virtualenvwrapper seems to provide an answer, but I would prefer not use external programs.

6
  • 1
    Please show us what you tried and what errors you got exactly. What package / program is this? What environment variable is it looking for? Commented Nov 5, 2012 at 11:19
  • virtualenv doesn't need to read your bash environment variables, just add the export instructions as detailed in the setup guide you linked to, then open a new terminal where those environment variables will be defined by the shell. Commented Nov 5, 2012 at 12:08
  • If I do the export directly in the virtualenv console, it works during the session only. The tutorial says I've to put the export in the ~/.bashrc, which is not read by a virtualenv. So where do I have to put it ? Commented Nov 5, 2012 at 12:58
  • .bashrc is read by your shell, and it'll be set for every session. Commented Nov 5, 2012 at 12:59
  • Ok. I get it. Isn't it dirty to export even when you don't need it ? Commented Nov 5, 2012 at 13:17

2 Answers 2

10

if you add to opus-env/bin/activate

OPUS_HOME="some value"
export OPUS_HOME

It should work (your solution 3). Of course it will not be applied to currently running processes.

Try to exit current virtualenv shell session, start new shell session, activate modified virtualenv in that new session. Before starting your program, verify environment:

env | grep OPUS_HOME
Sign up to request clarification or add additional context in comments.

Comments

0

Hmm, maybe use:

~virutalenv/bin/python opus.py

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.