Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Distributing python application

Tags:

python

I am writing a quite large Python application; the application is actually to a large part a wrapping of several shared libraries written in C and C++(Qt). I am 'installing' this without administrator rights, so everything including shared libraries, binary and also Python modules must be in non-standard locations, i.e. I have a situation like this:

  1. Shared libraries in /funny/path/lib
  2. Python modules installed in /funny/path/python/lin
  3. The python interpreter itself might also be in /nonstandard/location

The whole thing is distributed as open source, and I need to find a reasonably elegant and simple way to set the necessary environment variables. The whole thing is distributed with version control software; so the environment variables must be set in some 'local addition' i.e. something like:

#!/bin/bash
export LD_LIBRARY_PATH /funny/path/lib:$LD_LIBRARY_PATH
export PYTHONPATH /funn/path/python/lib:$PYTHONPATH

# 
exec python main.py

But I am programming in Python for a reason - I detest these shell scripts. Any views on the most elegant way to do this would be nice.

Joakim

like image 783
user422005 Avatar asked Apr 01 '11 21:04

user422005


1 Answers

Why waste time detesting shell scripts?

Since you won't install in a standard location, (and can't seem to get sys admins to install needed packages in standard locations) that's almost your only alternative.

You can set the PYTHONPATH from within Python. It's in sys.path. Setting an environment variable (like LD_LIBRARY_PATH) is harder, because Linux limits the ways in which applications can change the environment.

You can use os.exec to run a process in a modified environment. It's a little odd using Python to then do os.exec..e() to invoke Python, but it is an easy way to set an additional environment variable.

like image 159
S.Lott Avatar answered Sep 18 '22 13:09

S.Lott