Frans Englich wrote: > This is silly. How do I access data files I've installed with distutils? In a > portable, generic way, I want to find out what is the following path on most > systems: > > /usr/local/lib/python2.4/lib/site-packages/foo/bar.txt > > How do I figure out the rest, if I know foo/bar.txt? sys.prefix doesn't get me > far. > > I've googled, and looked in the python reference. I must be blind if the > distutils section[1] covers this.
It doesn't, because distutils doens't do this. The data_files option to distutils is pretty limited, is buggy, and if you override the data dir, distutils has absolutely no way to let the Python code know about it. Once or twice I've thought about making a patch, but it's a difficult problem since different parts of distutils need to communicate to make it work, in a way distutils engine doesn't support. Workarounds: Probably the most straightforward way is to just assume the data files are in the default place, but provide a way to override with an environment variable. If the user overrides the data dir when installing, then it's his or her responsibility to define the environment variable declaring where the data is. The second workaround is to inspect the distutils structure (that which is returned by setup), find out where the data dir is, and create a Python module that sets the data file location. I did this for a certain package I wrote. I posted this example here in comp.lang.python a while back: http://tinyurl.com/5qgsw -- CARL BANKS -- http://mail.python.org/mailman/listinfo/python-list