Where to put data

Michael Torrie torriem at gmail.com
Wed Jan 25 22:30:54 EST 2012

On 01/25/2012 03:29 PM, bvdp wrote:
> Right now my program does a search for modules in "all the normal
> places", which seems to work for windows, mac and linux. Once the
> modules are found I just insert that location into sys.path[0].
> Which permits the modules to reside anywhere on the HDD. However, I
> have feeling that this isn't quite pythonic

Unless you are writing a python library that will be used by others, I
don't think that where you put your files has anything to do with being
"pythonic" or not.  Just do what works for your OS.

On Linux, many packages written in many languages have to deal with the
problem of where to put their files.  For example, firefox, even when
installed as a package on Fedora, puts just about everything in
/usr/lib/firefox-#.#, and then symlinks the start binary back into
/usr/bin.  Other packages, such as Calibre, put things in
/usr/lib/calibre (most python modules go here), and some things like
extension scripts in /usr/share/calibre.  Other packages usr
/usr/libexec/packagename/.  In the case of both firefox and calibre, if
you install from tarball it makes a "firefox" or "calibre" folder in a
place of your choosing and dumps its stuff inside, sometimes with a
mini-unix directory structure (bin, share, lib etc).

On Mac of course, you can put everything in your application bundle.
That's how most standalone apps written in python work.

On Windows you could stick all your python modules in your application's
directory in Program Files.

More information about the Python-list mailing list