【问题标题】:Python package published with poetry is not found after install安装后找不到随诗发布的Python包
【发布时间】:2020-01-10 13:05:10
【问题描述】:

在过去的几天里,我正在研究一个 python 模块。到目前为止,我在许多其他项目中使用poetry 作为包管理工具,但这是我第一次想将包发布到 PyPI。

我能够运行poetry buildpoetry publish 命令。我还能够安装已发布的软件包:

$ pip3 install git-profiles
Collecting git-profiles
  Using cached https://files.pythonhosted.org/packages/0e/e7/bac9027effd1e34a5b5718f2b35c0b28b3d67f3809e2f2981b6c7b58963e/git_profiles-1.1.0-py3-none-any.whl
Installing collected packages: git-profiles
Successfully installed git-profiles-1.1.0

但是,在安装之后,我无法运行我的包:

$ git-profiles --help
git-profiles: command not found

我的项目结构如下:

git-profiles/
├── src/
│   ├── commands/
│   ├── executor/
│   ├── git_manager/
│   ├── profile/
│   ├── utils/
│   ├── __init__.py
│   └── git_profiles.py
└── tests

我尝试在 pyproject.toml 文件中使用不同的脚本配置,但安装后我一直无法使其工作。

[tool.poetry.scripts]
poetry = "src:git_profiles.py"

[tool.poetry.scripts]
git-profile = "src:git_profiles.py"

不知道这是python/pip路径/版本的问题还是我需要在配置文件里改一下。

如果有帮助,this 就是我所说的 GitHub 存储库。该包也发布on PyPI

【问题讨论】:

    标签: python git publish pypi python-poetry


    【解决方案1】:

    诗歌的scripts 部分环绕setuptoolsconsole script definition。因此,入口点名称和您为其指定的调用路径需要遵循完全相同的规则。

    简而言之,控制台脚本或多或少地从 shell 执行此操作:

    import my_lib  # the module isn't called src, that's just a folder name
                   # the right name to import is whatever you put at [tool.poetry].name
    
    my_lib.my_module.function()
    

    如果给定名称my-lib-call(名称可以与您的模块相同,但不必如此)将这样写:

    [tool.poetry.scripts]
    my-lib-call = "my_lib.my_module:function"
    

    适应您的项目结构,以下应该可以完成工作:

    [tool.poetry.scripts]
    git-profile = "git-profiles:main"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-11
      • 1970-01-01
      • 2021-06-13
      • 2020-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-05
      相关资源
      最近更新 更多