Skip to content

Instantly share code, notes, and snippets.

@hpoggie
Last active February 5, 2019 02:46
Show Gist options
  • Save hpoggie/5daf2e520a8ac0df42f020a759830924 to your computer and use it in GitHub Desktop.
Save hpoggie/5daf2e520a8ac0df42f020a759830924 to your computer and use it in GitHub Desktop.

1. Make sure the files are in the packaged version

Either put include_package_data=True in your setup.py and have a MANIFEST.in with something like

include package/models/*
include package/textures/*.png

Or in setup.py do

package_data={
    'models': ['*'],
    'textures': ['*.png']
}

Do not do both. include_package_data will override package_data.

See Also: https://stackoverflow.com/questions/11848030/how-include-static-files-to-setuptools-python-package

2. Use pkg_resources

To get the actual path of a file, use pkg_resources.resource_filename(__name__, filename).

See also: https://setuptools.readthedocs.io/en/latest/pkg_resources.html#resource-extraction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment