问题描述
基本上,有两种方法可以通过setup.py
将Python控制台脚本安装到我的路径中:
setup(
...
entry_points = {
'console_scripts': [
'foo = package.module:func',
],
}
)
和
setup(
...
scripts = [
'scripts/myscript.sh'
]
)
有什么区别?我看到第一种方法允许我为脚本选择漂亮的特定名称,但是还有其他区别吗?不同的原始用途,兼容性(setuptools,distutils,...?),用法,...?我很困惑,精心准备的详细答复可以帮助我(可能还有其他人)正确理解所有这一切.
(出色)点击包的文档建议使用
使用入口点而不是脚本的一些原因- 跨平台兼容性和
- 避免让解释器将
__name__
分配给__main__
,这可能导致代码两次导入(如果另一个模块导入了您的脚本)
单击是实现用作entry_points
的功能的好方法,
There are basically two ways to install Python console scripts to my path by setup.py
:
setup(
...
entry_points = {
'console_scripts': [
'foo = package.module:func',
],
}
)
and
setup(
...
scripts = [
'scripts/myscript.sh'
]
)
What are the differences? I see the first approach allows me to choose nice, specific name for my script, but are there any other differences? Different original purposes, compatibility (setuptools, distutils, ...?), usage, ...? I am quite confused and a nice elaborated reply could help me (and probably also others) to properly understand all this.
The docs for the (awesome) Click package suggest a few reasons to use entry points instead of scripts, including
- cross-platform compatibility and
- avoiding having the interpreter assign
__name__
to__main__
, which could cause code to be imported twice (if another module imports your script)
Click is a nice way to implement functions for use as entry_points
, btw.
这篇关于setup.py中的entry_points/console_scripts和脚本之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!