title: Troubleshooting pkg_resources.DistributionNotFound error
body: <p>Why does <a href="https://github.com/maphew/scraps/tree/master/bug-dist-not-found" rel="nofollow noreferrer">this simple program</a> result in a <code>pkg_resources.DistributionNotFound</code> error when run and how do we fix it?</p>
  
  <pre><code>#setup.py
  from setuptools import setup
  
  setup(name='my_project',
      version='0.1.0',
      packages=['my_project'],
      entry_points={
          'console_scripts': [
              'my_project = my_project.__main__:main'
          ]
       },
  )
  </code></pre>
  
  <p>.</p>
  
  <pre><code>##my_project/__main__.py
  
  import sys
  
  def main(args=None):
       print("Do Something")
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p><strong>Build:</strong> <code>python setup.py install --root=target --prefix=usr</code><br>
  <strong>Run:</strong> <code>.\target\usr\Scripts\my_project.exe</code></p>
  
  <h3>Result</h3>
  
  <pre><code>Traceback (most recent call last):
    File "D:\code-maphew\scraps\bug-dist-not-found\target\usr\Scripts\my_project-script.py", line 6, in &lt;module&gt;
      from pkg_resources import load_entry_point
    File "C:\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\pkg_resources\__init__.py", line 3105, in &lt;module&gt;
      @_call_aside
    File "C:\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\pkg_resources\__init__.py", line 3089, in _call_aside
      f(*args, **kwargs)
    File "C:\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\pkg_resources\__init__.py", line 3118, in _initialize_master_working_set
      working_set = WorkingSet._build_master()
    File "C:\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\pkg_resources\__init__.py", line 578, in _build_master
      ws.require(__requires__)
    File "C:\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\pkg_resources\__init__.py", line 895, in require
      needed = self.resolve(parse_requirements(requirements))
    File "C:\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\pkg_resources\__init__.py", line 781, in resolve
      raise DistributionNotFound(req, requirers)
  pkg_resources.DistributionNotFound: The 'my-project==0.1.0' distribution was not found and is required by the application
  </code></pre>
  
  <p>This Q is similar to <a href="https://stackoverflow.com/questions/35457144/pkg-resources-distributionnotfound-when-using-a-module-installed-from-a-bdist-rp">pkg_resources.DistributionNotFound when using a module installed from a bdist_rpm</a>, but not building an RPM. In that Q using <code>--prefix</code> solved the problem. That hasn't worked for me. I've replicated the same problem on Windows 10, Linux Mint, and Debian.</p>
  
  <p>Full code in a repo here: <a href="https://github.com/maphew/scraps/tree/master/bug-dist-not-found" rel="nofollow noreferrer">https://github.com/maphew/scraps/tree/master/bug-dist-not-found</a></p>