How do I distribute my pip package with data files correctly?
Check that your file is properly distributed when installing the package.
sys.prefix
will not locate "your" package. The__file__
attribute of the module points to the__init__.py
file. You can use this for the base path as in:import osimport mymodulesrc = os.path.join(os.dirname(mymodule.__file__), 'data/1.txt')def get(): with open(src) as f: return f.read().strip()