使用pypi将脚本打包成命令行

Published on Aug. 22, 2023, 12:10 p.m.

核心发布包时候,添加如下

setup.py

setup(
    name=name, #修改包名字-
    version=version,
    description=description,
    author=author,
    author_email=author_email,
    url=url,
    # install_requires=read_requirements('requirements.txt'),  # 指定需要安装的依赖
    long_description=long_description,
    long_description_content_type="text/markdown",
    install_requires=[
        'pytorch-lightning>=1.4.0',
        'tkitAutoTokenizerPosition>=0.0.0.3',
        'pytorch-crf>=0.7.2',
        'transformers>=4.9.2',
        'tkitJson>=0.0.0.3',

    ],
    packages=['tkitTagger'],
    # 这里封装命令行操作
    entry_points = { 
        'console_scripts': ['taggerTrainer=tkitTagger.TaggerTrainer:main'], 
    }
    # scripts=['tkitTagger/TaggerTrainer.py'],
    )

 ```

# 脚本文件
./tkitTagger/TaggerTrainer.py

```python
from pytorch_lightning.utilities.cli import LightningCLI
from tkitTagger.model import autoModel

def main():
    cli = LightningCLI(autoModel,save_config_overwrite=True)

if __name__ == "__main__": 
  main()

Tags:

related content