使用诗歌运行Python模块

发布于 2025-01-20 04:29:20 字数 891 浏览 1 评论 0原文

我的 Makefile 中有一个命令,如下所示

run/webserver:
    PYTHONPATH=src venv/bin/python -m api

,项目结构如下所示

project/
    src/
       api/
            __init__.py
            __main__.py
    tests/
    Makefile

我使用基本的 piprequirements.txt 文件,但是决定转向诗歌。

我将 Makefile 更新为此

run/webserver:
    poetry shell
    poetry run python -m api

并且 pyproject.toml 包含此配置诗歌

[tool.poetry]
name = "project"
description = "project"
version =  "1.20.0"
homepage = "https://"
repository = "https://"
documentation = "https://"
authors = [""]
packages = [
    { include="src", from="." },
]

但是当我尝试运行该命令时

make run/webserver

它失败了,并显示

No module named api

什么可能是问题?

I have a command in my Makefile that looks like this

run/webserver:
    PYTHONPATH=src venv/bin/python -m api

and project structure that looks like this

project/
    src/
       api/
            __init__.py
            __main__.py
    tests/
    Makefile

I used basic pip with requirements.txt file, but decided to migrate to poetry.

I updated Makefile to this

run/webserver:
    poetry shell
    poetry run python -m api

And pyproject.toml contains this configuration poetry

[tool.poetry]
name = "project"
description = "project"
version =  "1.20.0"
homepage = "https://"
repository = "https://"
documentation = "https://"
authors = [""]
packages = [
    { include="src", from="." },
]

But when I try to run the command

make run/webserver

It fails with

No module named api

What might be the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千寻… 2025-01-27 04:29:20

The packages argument usually includes the name:

packages = [
    { include = "api", from = "src" },
]

https://python-poetry.org/docs/pyproject/#packages

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文