How to find where data files are installed for my Python program (was: Function for the path of the script?)

Ben Finney ben+python at benfinney.id.au
Sun Oct 27 00:28:28 EDT 2013


Chris Angelico <rosuav at gmail.com> writes:

> It's very common to want to know what directory you're in - it's a
> good way to find data files.

That's a naive way to do it (though it's often good enough, for a
program only used on one system).

For programs intending to be used across many systems, the data files
often shouldn't be placed in the same directory as the program.

On systems conforming to the Filesystem Hierarchy Standard, it's
forbidden: programs go in a platform-specific location
<URL:http://refspecs.linuxfoundation.org/FHS_2.3/fhs-2.3.html#USRLIBLIBRARIESFORPROGRAMMINGANDPA>,
while platform-independent data files go in a separate location
<URL:http://refspecs.linuxfoundation.org/FHS_2.3/fhs-2.3.html#USRSHAREARCHITECTUREINDEPENDENTDATA>.

The ‘package_data’ feature of Distutils (originally from Setuptools)
<URL:http://docs.python.org/2/distutils/setupscript.html#installing-package-data>
doesn't help with this. The specified files are simply installed in a
subdirectory of the platform-specific program location, which violates
the FHS as described above.

So, what facility is there in Python to:

* allow the operating system to set separate installation locations for
  the program versus the data files; and

* allow the program to interrogate the operating system for where its
  data files are installed

in a way that lets the programmer ignore the specifics of each operating
system, while leaving it up to the system administrator to decide to
place data files separate from program files at install time?

-- 
 \         “I still have my Christmas Tree. I looked at it today. Sure |
  `\               enough, I couldn't see any forests.” —Steven Wright |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list