Exec: python: not found

Hello,

I’ve been developing a python project of mine that I want to distribute using SNAP but I’m having problems that I have spent ages trying to resolve.

My YAML:

apps: 
  pihole-panel:
    command: python $SNAP/bin/pihole_panel

parts:
  my-part:
    # See 'snapcraft plugins'
    plugin: python
python-version: python3

Error: /snap/pihole-panel/23/command-pihole-panel.wrapper: 6: exec: python: not found

I’ve also tried:
command: python bin/pihole_panel
command: bin/pihole_panel # creates similar error about pihole_panel not in “prime” folder.

My python files all have #!/usr/bin/env python3 at the top and you can see my folder structure and code here.

Thanks a lot

The problem you’re hitting is that you’re telling snapcraft that you have a Python project, but you actually have a couple of scripts written in Python. You have a couple of options

  1. use setuptools and friends to create a Python project, then try snapping it using the python plugin
  2. Keep the simple nature of your scripts, and use the dump plugin with e.g.
    stage-packages:
    • python3-gtk
1 Like

the binary to call is also python3 and not python as any of these methods would use packages from Ubuntu.

1 Like

Thank you both for your help.

I have rebuilt my project directory structure like so:

  • pihole-panel
    • bin
      • pihole-panel (bash script calls main.py)
    • pihole-panel
      • main.py
      • gtk_assistant.py
    • snap
      • snapcraft.yaml

My YAML:

apps:
pihole-panel:
command: bin/pihole-panel

parts:
my-part:
# See ‘snapcraft plugins’
plugin: python
python-version: python3

wrapper:
plugin: dump
source: .
stage:

  • bin/pihole-panel

My bin/pihole-panel bash script goes like this:

#!/bin/bash
echo “Test 1… 2… 3…”
BINPATH=dirname $0
python3 “$BINPATH/…/pihole-panel/main.py” $@

I can now build successfully and install but when I run “pihole-panel” I receive the error “/snap/pihole-panel/30/command-pihole-panel.wrapper: 6: exec: /snap/pihole-panel/30/bin/pihole-panel: Permission denied”

Now I’m sort of aware I may have to stage my python files? but taking it a step at a time so I placed an echo in the bash script to determine if the error is indeed caused by the bash script and not something it calls and it definitely cannot access the bash script.

if using dump, you need to chmod +x pihole-panel in the source or by doing an override-build (the former is more straightforward).

Great stuff that solved that issue.

I’m now getting this error when I run the application:

Traceback (most recent call last):
  File "/snap/pihole-panel/41/bin/../pihole-panel/main.py", line 8, in <module>
    gi.require_version('Gtk', '3.0')
  File "/snap/pihole-panel/41/usr/lib/python3/dist-packages/gi/__init__.py", line 102, in require_version
    raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace Gtk not available

I have smart searched GitHub for everyone who is using Python/GTK in their apps and this is the most complete list I could compile and also no one is using fancy tricks in their YAML to make it work.

My YAML:

build-packages:
  - python3-dev
  - libgirepository1.0-dev
#              - python3-gi
  - libglib2.0-dev
  - libgtk-3-dev
  - yelp-tools
  - intltool
  - autoconf

apps:
  pihole-panel:
    command: bin/pihole-panel
        
parts:
  my-part:
    # See 'snapcraft plugins'
    plugin: python
    python-version: python3
    stage-packages:
    - python3
    - gobject-introspection
    - gir1.2-gtk-3.0
    - gir1.2-glib-2.0
    - python3-gi

  wrapper:
    plugin: dump
    source: .
    stage:
      - bin/pihole-panel
      - pihole-panel/main.py
      - pihole-panel/gtk_assistant.py

My Main.py:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject

if you want to use GTK3 from your application then it is strongly recommended to depend on the desktop-gtk3 part and use the desktop-launch helper:

parts:
  wrapper:
    after: [desktop-gtk3]
    ... # the rest of your part here

apps:
  pihole-panel:
    command: desktop-launch $SNAP/bin/pihole-panel
    desktop: ... # you need a .desktop file either in your snap whose path in your snap is written here, or
      # omit this statement and make sure there is a file in your source at snap/gui/pihole-panel.desktop
    plugs:
      - desktop
      - x11
      - wayland