Inkscape.org
Creating New Extensions Use inkscape command in AppImage, need help
  1. #1
    rktech rktech @rktech

    I made/reworked a extension to generate G-Code for laser engraving running up to inkscape 1.1.2 (Linux install via PPA). Now I tried the newer Versions up to 1.2.2 with AppImage an run into trouble when calling the "inkscape" command to generate a raster PNG image.

    When I did this Python Code in the Extension:

    command='inkscape --version'
    p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    return_code = p.wait()
    stdout, stderr = p.communicate()

    It works fine in the PPA install but fail with stderr =  "inkscape: error while loading shared libraries: libboost_filesystem.so.1.71.0: cannot open shared object file: No such file or directory" in the AppImage

    A test showed that when I use the usr/bin/inkscape inside the AppImage (When inkscape is just running e.g /tmp/.mount_InkscafHsnlH/usr/bin/inkscape --version) from command line, I got the same error.

    If I use "/<PathToAppImage>/Inkscape-b0a8486-x86_64.AppImage --version" It works as expected.

    My Question now, what did I do wrong, or:
    - how can I access the usr/bin/inkscape command inside the AppImage from my Python extension?

  2. #2
    rktech rktech @rktech
    *

    Thank you for your answer, as I see, there is only a "workarround" possible, where I need to know the name and location of the AppImage file. Because I like that this extension could be used without modifying it because of the used AppImage I did now use this approach:

    • Check, if I get a version with "inkscape --version"
    • If not, check if I run in a Linux system, then I search in the process list, if there is something starting with "inkscape" and ending with ".AppImage"
    • Then I check if this prozess will answer correctly of the version parameter

    If someone has to solve the same issue here is the code snippet:
     

    inkscape_command = 'inkscape'
    inkVersion = '0.0.0'
    command='%s --version'%(inkscape_command)
    p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    return_code = p.wait()
    stdout, stderr = p.communicate()
    m = re.search('Inkscape\s([0-9]*)\.([0-9]*).([0-9]*)\s', stdout.decode('utf8'))
    if m:
        inkscape_major = int(m.group(1))
        inkscape_mid =   int(m.group(2))
        inkscape_minor = int(m.group(3))
        inkscape_version = inkscape_major * 1000000 + inkscape_mid * 1000 + inkscape_minor
        inkVersion = "%i.%i.%i"%(inkscape_major, inkscape_mid, inkscape_minor)
    
    # search for a running AppImage instance on Linux systems
    if sys.platform.startswith('linux'):
        command='ps -xao command | grep -oe ".*\/[iI]nkscape.*\.AppImage"'
        p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        return_code = p.wait()
        stdout, stderr = p.communicate()
        commands = stdout.decode('utf8')
    
        for tmp_command in commands.splitlines():
            p = subprocess.Popen(tmp_command+' --version', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            return_code = p.wait()
            stdout, stderr = p.communicate()
            
            m = re.search('Inkscape\s([0-9]*)\.([0-9]*).([0-9]*)\s', stdout.decode('utf8'))
            if m:
                tmp_inkscape_major = int(m.group(1))
                tmp_inkscape_mid =   int(m.group(2))
                tmp_inkscape_minor = int(m.group(3))
                tmp_inkscape_version = tmp_inkscape_major * 1000000 + tmp_inkscape_mid * 1000 + tmp_inkscape_minor
                tmp_inkVersion = "%i.%i.%i"%(tmp_inkscape_major, tmp_inkscape_mid, tmp_inkscape_minor)
            else:
                tmp_inkscape_version = 0
    
            if tmp_inkscape_version > inkscape_version:
                inkscape_command = tmp_command
                inkscape_version = tmp_inkscape_version
                inkVersion = tmp_inkVersion
                inkscape_major = tmp_inkscape_major
                inkscape_mid = tmp_inkscape_mid
                inkscape_minor = tmp_inkscape_minor
    
    # ......
    # your code here
    # ......
    
    # to call the inkscape command check if "inkscape_version" > 0 
    # then you can call "inkscape_command" with parameters
    # e.g.
    
    if inkscape_version > 0:
        command='%s <.... list of inkscape parameter .....>'%(inkscape_command)
        p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        return_code = p.wait()
        stdout, stderr = p.communicate()
        # .....
    
    

     

     

     

Inkscape Inkscape.org Inkscape Forum Creating New Extensions Use inkscape command in AppImage, need help