Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've got a Python script that I want to be started on boot. Putting a command in rc.local attempts to run the script, but fails because the script can't find the libraries on which it depends. These libraries are in a non-standard location. Normally, this isn't a problem because I specify these locations by setting up the PYTHONPATH environment variable in /etc/environment.

I tried specifying PYTHONPATH in rc.local (a non-optimal solution anyway because I'd like to specify it system-wide for all users in one place, ie, /etc/environment) which partly cures the problem. But it's still failing for one library (Quick2Wire) where the included file is in a sub-dir. PYTHONPATH includes the path:

/usr/local/lib/cr/python/quick2wire-python-api/src

The actualy include file is:

/usr/local/lib/cr/python/quick2wire-python-api/src/quick2wire/i2c.py

Normally, Python has no problem knowing it needs to look in the quick2wire sub-dir.

I guess I can setup a special version of PYTHONPATH in rc.local just to get this script to run and then have the version in /etc/environment replace it. Just wondered if there's a more elegant solution.

share|improve this question
    
Have you considered using a virtualenv? –  Salem Nov 5 '12 at 20:40
add comment

2 Answers 2

export PYTHONPATH=</blah/blah> python /usr/local/lib/cr/python/quick2wire-python-api/src/quick2wire/i2c.py 

the above should do the trick.

Else you can create a script ( .sh ) with above content and call the script from rc.local ;)

share|improve this answer
add comment

Try

export PYTHONPATH=</blah/blah> ;  python /usr/local/lib/cr/python/quick2wire-python-api/src/quick2wire/i2c.py 

Note that you must add ';' between two commands.

share|improve this answer
1  
If this was supposed to be a comment to the answer of gnuyoga, then please propose that as an edit to the answer. It seems an error in his post. –  gertvdijk Jun 28 '13 at 11:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.