How do I distribute my pip package with data files correctly? How do I distribute my pip package with data files correctly? python-3.x python-3.x

How do I distribute my pip package with data files correctly?


  1. Check that your file is properly distributed when installing the package.

  2. 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()