GNOME Builder + Python: How can I import python packages?

Hello! So I’m very new to using Builder and GTK and I am kind of lost on why Builder doesn’t recognize packages installed using pip. For one of my projects I needed to use pynput so I just:
pip3 install pynput
but Builder gives a ModuleNotFound error when I try to import it. Is there something else I should do when using external python packages with Builder?
I tried searching and looked at the docs but couldn’t find anything helpful. Thanks in advance!

Hi! :slight_smile:

How are you building your app (buildsystem-wise)? Did you use one of Builder’s project templates? What I assume is happening is that Builder is using the template’s flatpak manifest, which can’t access your host python libraries because Flatpaks are in a sandbox. So you’d need to either switch to a host build (in the Build Configuration with the top-left header bar button, switch to the non selected one in the sidebar), or build your python module in the flatpak manifest, with this tool.

1 Like

I am using the GNOME Application template of Builder for my project and from what I understand, it uses the Meson buildsystem.

I tried both, the first one didn’t work (which actually I don’t know why it didn’t, it still can’t find the package although it is installed on my system). The second one using the tool almost worked but when I put the json in my project folder (and add it as a module in the main project json) it can’t find pynput on pip while building:
which is weird since pynput does exist on pip and
pip3 install pynput
works just fine normally.

My best guess is that may be using Python 2 somehow?

Hmm, yeah that seems like the case since it also doesn’t work on the host build but if I take a look at src/
it is looking for python3 (I think?) so I am kinda confused here. Is there a way to check which python version the project is using? or a way to change it?

I’m confused though because seems to indicate it’s python3 compatible.

What command did you use here? You need to specify a full version requirement for flatpak-pip-generator, not just the pip package name.

I also tried with version like so:
python pynput==1.7.3
but well:

Also I just tried with a random different package ( and it actually worked with flatpak tho it didn’t work in the host build. So seems like the issue in the flatpak build has something to do with pynput but idk the issue with host build.

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