On 27 June 2015 at 19:52, Justin Uang <[email protected]> wrote: > What is the recommended way to get access to a data file in my package if > I'm using a wheel? pkg_resources seems like it's mainly useful because eggs > might be used in a zipped form, but for wheels, I'm guaranteed that the data > will be unpacked into a directory structure right? In that case, should I > just use __file__ to manually find the location of the file?
If you want to avoid a dependency on pkg_resources, you can use pkgutil.get_data (from the stdlib). It doesn't have as many features as pkg_resources, but it does the job in straightforward cases. Regarding zipped form, you are never guaranteed that your code is on the filesystem. Wheels always install unzipped, as you say, but deployment utilities like pyzzer/zipapp, or py2exe/cx_Freeze, bundle your application into a zip file for execution. So unless you want to document that your package doesn't support such deployment methods, you shouldn't assume you're installed to the filesystem (and hence you should avoid using __file__ and doing path manipulation on it). Paul _______________________________________________ Distutils-SIG maillist - [email protected] https://mail.python.org/mailman/listinfo/distutils-sig
