A workaround for the Python module search path issue on UnixAugust 8, 2008
One of the little challenges with writing Unix programs in Python is
the search path problem. The natural structure of Python programs is to
split functionality up into a bunch of modules and then (The normal Python search path for The obvious solution is to have your program start off by adding its
module directory to It turns out that there is a simple workaround, hinted at by the aside there: put the Python main program into its library directory along with the rest of its modules, and turn the command that gets installed into the binary directory into a tiny shell script that is just:
This results in the library directory being added to the search path, because it is the directory that the actual Python program is being run from. (And you can be confidant that Python will know what that is, since the program is being started by absolute path.) It is easy to create this tiny shell script as part of your installation
process (when you're sure to know where the library directory is, since
you are about to put things in it). As a bonus, your main program can
still have a (Credit where credit is due: I didn't invent this trick. I believe I first saw it being used by a Python program on Fedora or one of the pre-Fedora Red Hat version.) (One comment.)
Written on 08 August 2008.
|
These are my WanderingThoughts GettingAround This is part of CSpace, and is written by ChrisSiebenmann. * * * Atom feeds are available; see the bottom of most pages. Categories: links, linux, programming, python, snark, solaris, spam, sysadmin, tech, unix, web |