[Python] Is it possible to install submodules of a python package dynamically?

Discussão em 'Python' iniciado por Stack, Agosto 29, 2025.

  1. Stack

    Stack Membro Participativo

    I have a very complex Python library that is used by several people/projects for different purposes.

    The structure is basically the same as many Python libraries, but I would like to give the ability of a partial install.

    project_name/
    |__ package
    | |__ submodule1
    | | |__ __init__.py
    | |__ submodule2
    | | |__ __init__.py
    | |__ submodule3
    | | |__ __init__.py
    | |__ submodule4
    | | |__ __init__.py
    | |__ __init__.py
    | |__ types.py
    |__ setup.cfg
    |__ setup.py


    I would like to give people the ability to people to install everything, or what they really require, because they are not dependent.

    I tried several options like:


    • Hacking packages=find_packages(*) by myself, but I would like something more official. It is not my intention to split into several Git repositories.


    • Customizing pip install by using the cmdclass with a custom install option, but, AFAIK, this is deprecated in pip now.


    • Intercepting somehow the extras_require to use it within packages and create something like pip install package[submodule1], but no luck either.

    Any professional suggestion is welcome :)

    Continue reading...

Compartilhe esta Página