Python-Flask inside Snap -> PackageNotFoundError

Hello,

currently im creating a Snap of my MQTT-Client Software for Smart Home IoT Devices.

The snap is also in the public Store under cubiemedia-mqtt-client (Edge)

I got the tool “cubiemedia-mqtt-client” to work (if all plugs are manually connected). It also has a WebTool for Overview and Configuration but it seems not possible to get Flask running inside the snap.

PackageNotFoundError: No package metadata was found for Flask

I found a similar problem:

But i could not get it to work with the suggested solutions.

Has anyone a hint for me?

Could you share the output of journalctl -ex after you try to run the snap? This command will produce the relevant error logs, and will give us a good idea if the package is not finding a file that it should.

You can share the logs as a paste using https://pastebin.ubuntu.com.

1 Like

The messages i get:

cubiemedia@ubuntu:~$ systemctl status snap.cubiemedia-mqtt-client.cubiemedia-webtool.service 
● snap.cubiemedia-mqtt-client.cubiemedia-webtool.service - Service for snap application cubiemedia-mqtt-client.cubiemedia-webtool
     Loaded: loaded (/etc/systemd/system/snap.cubiemedia-mqtt-client.cubiemedia-webtool.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Wed 2022-06-29 11:14:39 UTC; 4 weeks 1 days ago
    Process: 880 ExecStart=/usr/bin/snap run cubiemedia-mqtt-client.cubiemedia-webtool (code=exited, status=1/FAILURE)
   Main PID: 880 (code=exited, status=1/FAILURE)
1 Like

Steps to reproduce:

cubiemedia@ubuntu:~$ snap run --shell cubiemedia-mqtt-client
cubiemedia@ubuntu:/home/cubiemedia$ flask
Traceback (most recent call last):
  File "/snap/cubiemedia-mqtt-client/225/usr/bin/flask", line 33, in <module>
    sys.exit(load_entry_point('Flask==2.0.1', 'console_scripts', 'flask')())
  File "/snap/cubiemedia-mqtt-client/225/usr/bin/flask", line 22, in importlib_load_entry_point
    for entry_point in distribution(dist_name).entry_points
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 957, in distribution
    return Distribution.from_name(distribution_name)
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 548, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: No package metadata was found for Flask

Could you try adding the following tag to the python part in your snapcraft.yaml file?

build-environment:
      - PYTHONPATH: ${CRAFT_PART_INSTALL}/usr/lib/python3/dist-packages

Let me know if this does the trick.

Thank you @nuccitheboss for looking into this.

In the GitHub Repository you can see i added your suggestion. Hope it is the right spot.

It did not change the outcome. I think the build environment is not the right spot because this seems to be a runtime issue. For the main tool of this snap i also had to add following lines to make it work:

snap_path = os.getenv('SNAP')
sys.path.append(f'{snap_path}/src')
sys.path.append(f'{snap_path}/usr/lib/python3/dist-packages')
sys.path.append(f'{snap_path}/lib/python3.10/site-packages')

I also tried this for the flask app (webtool) but i could not make it work. Since im using core22 i also can not build it localy anymore that’s why every test is now build on snapcraft.io directly from github.

Maybe i should switch back to core20? But i have the feeling this will also not solve the issue.

Greetings