Running Inkscape 0.92 extensions with python3

✍️ Written on 2021-09-19 in 503 words.
Part of cs software-development Linux

Motivation

Since Inkscape 0.92, one can run extensions with a different python interpreter than the main application. I had to use this feature, because somehow Inkscape on my Ubuntu 20.04.3 LTS still used python 2.7.18 which the AxiDraw extension was not happy with.

The issue

Inkscape extension AxiDraw python interpreter

“AxiDraw software must be run with python 3.6 or greater”

Investigation

  1. The file axidraw_deps/axidrawinternal/_init_.py of the AxiDraw extension contains a check of the python version:

    # Bail out if python is less than 3.5
    import sys
    MIN_VERSION = (3, 6)
    if sys.version_info < MIN_VERSION:
        sys.exit("AxiDraw software must be run with python 3.6 or greater.")
  2. The extension interpreters clearly document which interpreter is chosen.

  3. The file axidraw.inx specifies python as interpreter:

    <script>
    <command reldir="extensions" interpreter="python">axidraw_control.py</command>
    </script>
  4. Since ~/.config/inkscape/preferences.xml does not list a python-interpreter, my deprecated python interpreter seems to be chosen.

Now we understand all building blocks. Time for a fix!

The fix

Open the file ~/.config/inkscape/preferences.xml and look for a <group> with id="extensions". Add the following attribute:

python-interpreter="/usr/bin/python3"

(Assuming /usr/bin/python3 is the interpreter, you want to use.) In my case, the lines look as follows.

  <group
     id="extensions"
     python-interpreter="/usr/bin/python3"
     org.inkscape.output.pdf.cairorenderer.PDFversion="PDF-1.5"
     org.inkscape.output.pdf.cairorenderer.resolution="96"
     org.inkscape.output.pdf.cairorenderer.bleed="0"
     org.inkscape.input.gdkpixbuf.jpg.link="link"
     command.evilmadscientist.axidraw-manager.copies="1"
     command.evilmadscientist.axidraw-manager.page_delay="15"

Conclusion

  1. Current Inkscape versions can use a different python interpreter than GIMP itself.

  2. One needs to understand that there is a level of indirection: python in the INX file will look up python-interpreter in the preferences.xml file.

  3. The fix makes Inkscape run extensions with python3.