是否可以使用 pip 一次安装模块和包装器脚本?
Is possible to install a module and a wrapper script using pip at once?
到目前为止,我以这种方式与人分享了我的 Python 程序:
- 用函数
写一个模块my_module
- 编写一个包装器脚本
my_script
,它使用此模块和其他包,例如 argparse
- 在 PyPI 上发布
my_module
- 将软件推送到 Github,并附上说明如何安装的自述文件:
- 使用
pip install my_module
安装模块
- 从Github下载
my_script
并移动到PATH
变量指向的地方或运行本地python my_script
这种方式似乎不错,但我想知道是否可以一次性安装它,即 pip install my_software
一次安装所有东西。此外,重要的是能够在安装后键入 my_script
.
调用包装器脚本
发布此类软件的最佳秘诀是什么?
来自 Setuptools 文档:
https://setuptools.readthedocs.io/en/latest/setuptools.html#automatic-script-creation
[Specifying scripts in distutils used to be hard...] setuptools fixes
all of these problems by automatically generating scripts for you with
the correct extension, and on Windows it will even create an .exe file
so that users don’t have to change their PATHEXT settings. The way to
use this feature is to define “entry points” in your setup script that
indicate what function the generated script should import and run. For
example, to create two console scripts called foo and bar, and a GUI
script called baz, you might do something like this:
setup(
# other arguments here...
entry_points={
'console_scripts': [
'foo = my_package.some_module:main_func',
'bar = other_module:some_func',
],
'gui_scripts': [
'baz = my_package_gui:start_func',
]
}
)
请注意,如果脚本是与 setuptools 没有直接关系的构建过程的结果(您想在 pypi 上提供一个包,但想使用您的 cmake 工具链进行构建),您将需要覆盖install_scripts
class 来自 setuptools.command.install_scripts
到目前为止,我以这种方式与人分享了我的 Python 程序:
- 用函数 写一个模块
- 编写一个包装器脚本
my_script
,它使用此模块和其他包,例如argparse
- 在 PyPI 上发布
my_module
- 将软件推送到 Github,并附上说明如何安装的自述文件:
- 使用
pip install my_module
安装模块
- 从Github下载
my_script
并移动到PATH
变量指向的地方或运行本地python my_script
- 使用
my_module
这种方式似乎不错,但我想知道是否可以一次性安装它,即 pip install my_software
一次安装所有东西。此外,重要的是能够在安装后键入 my_script
.
发布此类软件的最佳秘诀是什么?
来自 Setuptools 文档:
https://setuptools.readthedocs.io/en/latest/setuptools.html#automatic-script-creation
[Specifying scripts in distutils used to be hard...] setuptools fixes all of these problems by automatically generating scripts for you with the correct extension, and on Windows it will even create an .exe file so that users don’t have to change their PATHEXT settings. The way to use this feature is to define “entry points” in your setup script that indicate what function the generated script should import and run. For example, to create two console scripts called foo and bar, and a GUI script called baz, you might do something like this:
setup(
# other arguments here...
entry_points={
'console_scripts': [
'foo = my_package.some_module:main_func',
'bar = other_module:some_func',
],
'gui_scripts': [
'baz = my_package_gui:start_func',
]
}
)
请注意,如果脚本是与 setuptools 没有直接关系的构建过程的结果(您想在 pypi 上提供一个包,但想使用您的 cmake 工具链进行构建),您将需要覆盖install_scripts
class 来自 setuptools.command.install_scripts