如果我通过setup.py中的entry_point创建console_scripts,则将创建此文件:
#!/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。
答案 0 :(得分:2)
我遇到了同样的错误。要解决此问题,必须更新PYTHONPATH
以添加站点目录。在Windows上,您将转到命令提示符并键入以下内容:
set pythonpath=<PATH_TO_SITE_DIR>
Mac是这样的:
export PYTHONPATH="${PYTHONPATH}:<PATH_TO_SITE_DIR>"
Here是有关该错误的更多信息。