Search code examples
pythonpython-poetry

run python module using poetry


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?


Solution

  • The packages argument usually includes the name:

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

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