
On 28 August 2014 21:33, Joost Molenaar <j.j.molenaar@gmail.com> wrote:
Question; would it help to use pkg_resources, or being able to specify locations relative to the python interpreter prefix?
Generally, I'd recommend putting resource files in the package directory and reading them via pkgutil.get_data (from the stdlib). The advantage of that is that it supports non-filesystem importers (such as zipfiles). pkg_resources lets you be a bit more flexible but at the cost of a runtime dependency on setuptools (which I personally find unacceptable, but YMMV). For projects that don't mind failing when run from anything other than the filesystem, you can use package.__file__ to get the filesystem location of your package and work from there - but that's zipfile-hostile and won't work with tools like cx_Freeze/py2exe/bbfreeze. If you are willing to restrict your code to only working when installed to the actual filesystem, you could also use sysconfig.get_path(name) to get the filesystem location of the various distutils locations (name='data' is where data_files are located, for example) and use that to locate your files. I'm not entirely sure why this would be better than using pkgutil, though. The key thing is to *not* try to force your data files into a fixed location that you then hard-code in your application. Paul