我见过一些 python 包的示例,这些包在从 pypi 之类的东西安装后,具有与该工具关联的 CLI。
两个示例:rasa(例如rasa init
)或streamlit(例如streamlit hello
)。
我有兴趣为我自己的包探索这个,我的要求是我不想在我的命令前面加上python
。例如,如上所示的 rasa init
,而不是 python rasa init
,但不可否认,我不知道这是如何在幕后发生的。
最佳答案
这是 streamlit
的 setup.py
的相关部分:
setuptools.setup(
...
entry_points={"console_scripts": ["streamlit = streamlit.cli:main"]},
...
# For Windows so that streamlit * commands work ie.
# - streamlit version
# - streamlit hello
scripts=["bin/streamlit.cmd"],
)
- 以下是
entry_points
的说明:Explain Python entry points? - 以下是
脚本
的说明:Python setuptools using 'scripts' keyword in setup.py - 这是一个关于 Pros and cons of 'script' vs. 'entry_point' in Python command line scripts 的问题
有趣的是,一些消息来源似乎声称 entry_points
在 Windows 上不起作用,而另一些消息来源则声称它是 scripts
在 Windows 上不起作用。就我个人而言,我一直在使用 entry_points
,它在 Windows 10 和 Linux 上都适用。
关于python - 从 pip 安装后没有 python 的 CLI 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66520880/