[Python] Managing sub packages with poetry

Discussão em 'Python' iniciado por Stack, Julho 15, 2025.

  1. Stack

    Stack Membro Participativo

    I have an old Django project, which uses PIP for package management. What Im trying is to migrate it to use Poetry instead of PIP.

    My project structure is like so:

    main-project-root/
    ├── requirements/
    │ └── dev.txt # pip-based dev dependencies
    │
    ├── src/
    │ └── myProj/
    │ ├── myProj/ # This is main Django app
    │ │ ├── __init__.py
    │ │ ├── settings.py
    │ │ ├── urls.py
    │ │ └── wsgi.py
    │ └── manage.py # Main project's manage.py
    │
    ├── lib/
    │ ├── mySubProj1/
    │ │ ├── pyproject.toml # Subproject-specific dependencies
    │ │ ├── poetry.lock
    │ │ ├── mySubProj1/ # Django app package inside
    │ │ │ ├── __init__.py
    │ │ │ ├── settings.py
    │ │ │ └── ...
    │ │ └── manage.py
    │ │
    │ ├── mySubProj2/
    │ │ ├── pyproject.toml
    │ │ ├── poetry.lock
    │ │ ├── mySubProj2/
    │ │ └── manage.py
    │ │
    │ └── mySubProj3/
    │ ├── pyproject.toml
    │ ├── poetry.lock
    │ ├── mySubProj3/
    │ └── manage.py
    │
    ├── pyproject.toml # Root pyproject for main project
    ├── poetry.lock
    └── README.md


    I have added all the needed packages into a separate poetry config file for each sub-project. My idea is when i execute: poetry install from the main project destination - to install all the sub-project pyproject.toml poetry configurations.

    However, I keep hitting an error:


    Installing the current project: main-project (0.1.0) Error: The current project could not be installed: No file/folder found for package main-project If you do not want to install the current project use --no-root. If you want to use Poetry only for dependency management but not for packaging, you can disable package mode by setting package-mode = false in your pyproject.toml file. If you did intend to install the current project, you may need to set packages in your pyproject.toml file.
    ​

    This is how my main pyproject.toml looks like:

    [project]
    name = "main-project"
    version = "0.1.0"
    description = ""
    authors = [
    {name = "Your Name",email = "you@example.com"}
    ]
    readme = "README.md"
    requires-python = ">=3.8"
    package-mode = false

    [tool.poetry.dependencies]
    mySubProj1 = {path = "lib/mySubProj1", develop = true}


    [build-system]
    requires = ["poetry-core>=1.0.0,<2.0.0"]
    build-backend = "poetry.core.masonry.api"


    And this is how my subProj1 pyproject.toml looks like:

    [project]
    name = "mySubProj1"
    version = "0.1.0"
    description = ""
    authors = [
    {name = "Test Test",email = "test@gmail.com"}
    ]
    license = {text = "Apache License 2.0"}
    readme = "README.rst"
    requires-python = ">=3.8"

    [tool.poetry]
    name = "mySubProj1"
    version = "0.1.0"
    description = ""
    authors = ["Test test <test@gmail.com>"]
    license = "Apache-2.0"
    readme = "README.rst"
    packages = [{include = "mySubProj1"}]

    [tool.poetry.dependencies]
    python = "^3.8"
    six = ">=1.17.0,<2.0.0"

    [build-system]
    requires = ["poetry-core>=1.0.0,<2.0.0"]
    build-backend = "poetry.core.masonry.api"

    Continue reading...

Compartilhe esta Página