This should be a very common question for developers who used "setup.py" to build installation packages and it should be asked before but I couldn't find the proper answer anywhere.
from distutils.core import setup
data_files=[('MyApp/CBV', ['myapp/data/CBV/training.cbv', 'myapp/data/CBV/test.cbv'])],
copying MyApp/data/CBV/training.cbv -> /usr/local/MyApp/CBV
copying MyApp/data/CBV/test.cbv -> /usr/local/MyApp/CBV
from setuptools import setup
my_data_file = pkg_resources.resource_filename(__name__, 'data/CBV/test.cbv')
By default, when installing a package as root, the data path is based on
sys.prefix plus your project name, I believe, so you can retrieve your files based on that.
You would be better off using the
setuptools extension to
distutils and use the
pkg_resources module Resource API to load data files. It comes with
setuptools for this very purpose.
You do want your data files included in the package for that to work best. See Including data files (in the setuptools documentation).
You can then load resource files with straight into a string with
resource_string for example:
from pkg_resources import resource_string foo_config = resource_string(__name__, 'foo.conf')