title: Alternative to using __file__ find the binary folder in my python package
body: <p>I published a library to PyPI ('nmrsim') that has the following structure (edited to only include the relevant files/folders):</p>
  
  <pre><code>nmrsim
  ├── nmrsim
  │   ├── __init__.py
  │   ├── bin
  │   │   ├── T1.npz
  │   │   ⋮
  │   │   └── T11.npz
  │   | 
  │   └── qm.py
  │   
  └── tests
      └── test_qm.py
  </code></pre>
  
  <p>The <code>bin</code> directory contains binaries (sparse matrices of partial solutions) for faster calculations. For <code>qm.py</code> to discover the <code>bin</code> directory regardless of where it's installed and called from (e.g. an end user's main app, the module's test suite <code>tests/test_qm.py</code>, an IDE...), references to <code>__file__</code> are used, e.g. in <code>qm.py</code>:</p>
  
  <pre><code>def _tm_cache(nspins):
      filename = f'T{nspins}.npz'
      bin_dir = os.path.join(os.path.dirname(__file__), 'bin')
      path = os.path.join(bin_dir, filename)
      try:
          T_sparse = sparse.load_npz(path)
          return T_sparse
      except FileNotFoundError:
          &lt;work around missing file&gt;
  </code></pre>
  
  <p>The library can be successfully pip-installed and used across platforms. However, using PyInstaller to create a 1-file frozen app fails because the <code>bin</code> directory isn't included. Looking through documentation for PyInstaller and PyOxidizer (a possible alernative), it seems that the use of <strong>file</strong> is problematic for "freezing" python apps. </p>
  
  <p>How might I refactor code such as this to avoid using <code>__file__</code>?</p>