1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Editable installations with non-Python files (src layout)

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

  1. Stack

    Stack Membro Participativo

    Let's say I have this file structure for a project called witty_name.

    witty_name
    ├── icons
    │ └── my_icon.png
    ├── pyproject.toml
    └── src
    └── witty_name
    ├── __init__.py
    └── main.py


    Notice the icons directory. I want to store all application icons in this folder.

    When I build the project, I'm going to end up with this structure:

    site-packages/witty_name
    ├── icons
    │ └── my_icon.png
    ├── __init__.py
    └── main.py


    This part is fine, I've got the build backend configured to make this structure. To make sure this works regardless of where I start witty_project from, I find the icons folder using __file__, as below

    # contents of main.py

    from os import path

    BASE_FOLDER = path.dirname(__file__)
    ICONS = path.join(BASE_FOLDER, "icons")


    def main():
    # use the icons folder here (or elsewhere)
    pass


    if __name__ == "__main__":
    main()


    Here's the problem: how do I run the project while developing it? If I try to run it normally (i.e. python src/witty_name/main.py), I'm going to get a FileNotFoundError because the code expects the icons directory to be next to main.py. If I do an editable install, it will copy the icons directory but not the other files, so I'll get a similar issue. If I do pip install ., I can run the project, but it won't update when I make changes unless I reinstall. Can I avoid this?

    The obvious solutions are:

    1. Put icons inside of src/witty_name.
      • I want to avoid this because these aren't source files, they are images.
    2. Re-run pip install . every time I make changes.
      • This defeats the purpose of using Python, since it's like I'm recompiling every time.
    3. Use symlinks.
      • This isn't an option because I'm on Windows without admin/developer rights, so I can't make symlinks.

    If anyone has ideas I would love to hear them! Also, is the first file structure reasonable for a Python GUI project? Thanks!

    Continue reading...

Compartilhe esta Página