Builder - what am I doing wrong?

I’m trying to use Builder to restart something I started a while ago… I’m trying to move something that worked well in gtk3 (done in VSCode) to gtk4 (using Builder).

I can’t get over the first hurdle.

I’ve got main.py file and a module called globals.py.

In main.py, if I add ‘import globals’ at the top the terminal reads ‘ModuleNotFoundError: No module named ‘globals’’

Why?? If I open the folder up in VSCode it’s very happy globals.py is there. It was always so simple! I can’t even find a ‘save project’ button in case it’s a refreshing problem… which I have found happen when I’ve deleted previous modules. Something disappears from the tree but the one I deleted is still there?

When I started the project I set it up as a gtk4 project using Python.

Thank you!

The correct syntax for import is:

from . import globals

or


from .globals import "className"

Thank you - I’m going to give gtk4 and builder another go this evening so I’ll try it out.

EDIT: “ModuleNotFoundError: No module named ‘globals’
Application exited” for both.

I would have thought Python is Python and what works in VSCode would work in all IDEs. I’ll just stick to gtk3.

The project seems to be using the meson build system.

So my guess would be that you might not have added the globals.py file to the sources, thus meson does not know that you need the file. Meson then doesn’t bring it along when you then “build” the program, and thus isn’t available when you run it.

Have a look inside the meson.build file in the src/ folder, it should contain something in the direction of:

books_sources = [
  '__init__.py',
  'main.py',
  'window.py',
]

adding the name of your sourcefile the should make it available using the syntax from the previous suggestion.

Yes, @HighKingofMelons is right. I use a different default directory structure and configure meson to package the entire src with install_subdir('src', install_dir: pkgdatadir).

I had forgotten that the directory structure model that Builder creates needs this addition to sources. This isn’t a python issue, it’s a question of how meson works in flatpak.

This was it, along with kriptolix’s reply. Thank you!

I tried so many things so many times but obviously not these two steps at the same time. Thanks

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.