#StackBounty: #pip #console-application #setup.py #pkg-resources fragile console script: pkg_resources.DistributionNotFound

Bounty: 50

If I create console_scripts via entry_point in setup.py, then this file gets created:

#!/home/myproject_cok_d/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'mylib','console_scripts','do-magic'
__requires__ = 'mylib'
import re
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script.pyw?|.exe)?$', '', sys.argv[0])
    sys.exit(
        load_entry_point('mylib', 'console_scripts', 'do-magic')()
    )

Unfortunately this script is fragile.

Sometimes I get exceptions like this:

Traceback (most recent call last):
  File ".../bin/do-magic", line 6, in <module>
    from pkg_resources import load_entry_point
  File ".../local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2999, in <module>
    @_call_aside
  File ".../local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2985, in _call_aside
    f(*args, **kwargs)
  File ".../local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3012, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File ".../local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 662, in _build_master
    ws.require(__requires__)
  File ".../local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 970, in require
    needed = self.resolve(parse_requirements(requirements))
  File ".../local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 856, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'PyPDF2==1.26' distribution was not found and is required by mylib

Is there a way to make my script (do-magic) more mature?

In this case: It does not need PyPDF2.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.