2

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.

guettli
  • 25,042
  • 81
  • 346
  • 663

1 Answers1

3

I ran into the same error. To solve this issue, you must update PYTHONPATH to add the site directory. On Windows you would go to your the command prompt and type this:

set pythonpath=<PATH_TO_SITE_DIR>

And Mac is this:

export PYTHONPATH="${PYTHONPATH}:<PATH_TO_SITE_DIR>"

Here is more information about the error.

xilpex
  • 3,097
  • 2
  • 14
  • 45
  • This is the correct answer to you problem. In the case of above question, this does not help. The PYTHONPATH is correct. There is just some version mismatch for library which does not matter at all for the console script (in this example called `do-magic`). – guettli Apr 05 '19 at 07:13