当前位置:   article > 正文

python打包两种方式:setup.py、pyproject.toml;entry_points、project.scripts 可执行的命令行_pyproject.toml vs setup.py

pyproject.toml vs setup.py

参考:
https://blog.csdn.net/qq_38844437/article/details/126628564
在这里插入图片描述

setup.py

https://click.palletsprojects.com/en/7.x/setuptools/#setuptools-integration

学习写法:https://github.com/myshell-ai/MeloTTS/blob/main/setup.py

yourscript.py:

import click

@click.command()
def cli():
    """Example script."""
    click.echo('Hello World!')
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

setup.py:



from setuptools import setup

setup(
    name='yourscript',
    version='0.1',
    py_modules=['yourscript'],
    install_requires=[
        'Click',
    ],
    entry_points='''
        [console_scripts]
        yourscript=yourscript:cli
    ''',
)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

pyproject.toml

参考:https://blog.csdn.net/qq_38844437/article/details/126628564

学习写法yolo:https://github.com/ultralytics/ultralytics/blob/main/pyproject.toml
https://packaging.python.org/en/latest/guides/writing-pyproject-toml/

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
#...
[project]
# ...
name = "apap"
version = "1.0"
requires-python = ">=3.8"
authors = [
    { email = "yangtze_lv@163.com" },
    { name = "Wenchao Lv" }
]
dependencies = [
    "setuptools==65.3.0",
    "wheel==0.37.1",
    "opencv-contrib-python==4.5.5.62",
    "opencv-python==4.5.5.62",
    "matplotlib==3.5.3",
    "numpy==1.23.2",
    "matplotlib==3.5.3"
]
# ...
[tool.setuptools.packages.find]
where = ["src"]
include = ["apap"]

[project.scripts]
apap = "apap.main:main"

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

在这里插入图片描述

entry_points、project.scripts 可运行的命令行

前面打包里setup.py设置了entry_points;pyproject.toml设置了project.scripts模块;安装后就可以有将Python模块转变为命令行工具

参考:https://blog.51cto.com/mouday/3040500

yolo ***
tts ***
apap ****
  • 1
  • 2
  • 3
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/505877
推荐阅读
相关标签
  

闽ICP备14008679号