Python sh: 0 can't open


I’m working on a new snap using a python3 script that calls on some bash scripts to run minecraft server from a menu.

Here’s the thing, and it’s probably obvious to many of you, I can’t get it to run inside my snap. I’ve tried several ways of calling the same commands in the snap (via the script) and I keep getting the same error listed above. Here’s the current snapcraft.yaml:

name: mc-server-installer
version: git
summary: Minecraft Server Downloader and Installer
description: |
    A Minecraft Server installer snap.  
grade: stable
confinement: strict

    command: python3 $SNAP/
      - network
      - home
      - network-bind

    source-type: git
    plugin: python
    python-version: python3
      - openjdk-8-jre-headless
      - wget
      - python3
      - openjdk-8-jre-headless
      - wget
      - python3

    plugin: copy

Here’s the python script (menu):

#!/usr/bin/env python3

import subprocess
import time
import os
import sys
def print_menu():       
    print (20 * "-" , "MC-SERVER-INSTALLER MENU" , 20 * "-")
    print ()
    print ("Choose the amount of RAM you need: ")
    print ()
    print ("1. 2GB Max allotment")
    print ("2. 4GB Max allotment")
    print ("3. 6GB Max allotment")
    print ("4. 8GB Max allotment")
    print ("5. 12GB Max allotment")
    print ("6. 16GB Max allotment")
    print ("7. 24GB Max allotment")
    print ("8. Exit")
    print ()
    print (67 * "-")
    print ()
while loop:
    choice = str(input("Enter your choice: "))
    choice = int(choice)
    if choice == 1:     
        print ("Starting server with 2GB max...")['sh','$SNAP/'])
    elif choice == 2:
        print ("Starting server with 4GB max...")
    elif choice == 3:
        print ("Starting server with 6GB max...")['sh','$SNAP/'])
    elif choice == 4:
        print ("Starting server with 8GB max...")['sh','$SNAP/'])
    elif choice == 5:
        print ("Starting server with 12GB max...")['sh','$SNAP/'])
    elif choice == 6:
        print ("Starting server with 16GB max...")['sh','$SNAP/'])
    elif choice == 7:
        print ("Starting server with 24GB max...")
    elif choice == 8:
        print ("Exiting. Goodbye!")
        print("Invalid choice, please choose a menu item.")

Any help is very much appreciated. I am so close to setting this snap free…I can feel it! :wink:


python will not know what $SNAP, you need to expand the variable for it to be resolved.


Even if the file structure is flat? All the scripts being called are in the same directory as the python menu. That’s what is confusing me a bit. I can run the same script(s) on my local system w/o error from the same directory. This version of the script shown is the last I had tried. Previously, $SNAP was omitted from the path.

So it looked like:['sh',''])

You’ll have to pardon my ignorance, I’m still learning.


why call python3 in the command stanza at all if you already have a hashbang inside the application anyway … I’d just make executable and drop the python3 call from the command: line …


use os.environ['SNAP'] to get $SNAP


Thanks to all of you for your input. I switched to bash and it’s working as intended.