脆弱的控制台脚本:pkg_resources.distributionnotfound



如果我通过setup.py中的entry_point创建console_script,则此文件将创建:

#!/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')()
    )

不幸的是,此脚本很脆弱。

有时我会得到这样的例外:

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

有没有办法使我的脚本(do-magic)更加成熟?

在这种情况下:它不需要pypdf2。

我遇到了相同的错误。要解决此问题,您必须更新PYTHONPATH才能添加站点目录。在Windows上,您将转到命令提示符并输入以下内容:

set pythonpath=<PATH_TO_SITE_DIR>

和mac是这样:

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

这是有关错误的更多信息。

相关内容

  • 没有找到相关文章

最新更新