Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the Python interpreter for Inkscape

I keep getting errors when using Inkscape that seem to imply that a python 2 vs 3 expectation isn't being met, though I have both of them installed. For instance, when I try to make a new document generated from a template, I get,

Traceback (most recent call last):
  File "empty_generic.py", line 82, in <module>
    c.affect()
  File "/usr/share/inkscape/extensions/inkex.py", line 285, in affect
    self.output()
  File "/usr/share/inkscape/extensions/inkex.py", line 272, in output
    self.document.write(sys.stdout)
  File "src/lxml/lxml.etree.pyx", line 2033, in lxml.etree._ElementTree.write (src/lxml/lxml.etree.c:63667)
  File "src/lxml/serializer.pxi", line 524, in lxml.etree._tofilelike (src/lxml/lxml.etree.c:134877)
  File "src/lxml/lxml.etree.pyx", line 324, in lxml.etree._ExceptionContext._raise_if_stored (src/lxml/lxml.etree.c:10737)
  File "src/lxml/serializer.pxi", line 441, in lxml.etree._FilelikeWriter.write (src/lxml/lxml.etree.c:133581)
TypeError: write() argument must be str, not bytes

where the last line seems to be just what I said-- usually this error is caused by running python 2 code with a python 3 interpreter, and can be fixed by simply passing the string object str as str.decode() or something. Obviously, though, editing the inkscape source code is not an ideal solution.

Also, when trying to generate a Voronoi diagram, I get

Traceback (most recent call last):
  File "voronoi2svg.py", line 36, in <module>
    import simplepath
  File "/usr/share/inkscape/extensions/simplepath.py", line 51
    raise Exception, 'Invalid path data!'
                   ^
SyntaxError: invalid syntax

which again seems like an obvious 2 vs. 3 error.

Is there a way to change the python interpreter being used by Inkscape?

like image 678
pretzlstyle Avatar asked Aug 27 '18 20:08

pretzlstyle


People also ask

How do I change Python interpreter?

Change the Python interpreter in the project settings Press Ctrl+Alt+S to open the IDE settings and select Project <project name> | Python Interpreter. Expand the list of the available interpreters and click the Show All link. Select the target interpreter.

What version of Python does Inkscape use?

The latest stable Inkscape version includes Python 2.6.

Do I need to install Python with Inkscape?

Do not use Python 2; the Inkscape extensions require Python 3. The python-interpreter line needs to point to your actual Python interpreter: The executable, not just a folder.; usually something ending with ".exe."

Is Inkscape written in Python?

Simple Inkscape Scripting makes it easy to automate repetitive drawing tasks. It defines a simple set of Python functions such as "rect" to draw a rectangle and "line" to draw a line.


1 Answers

I Actually found the answer to my issue from the Inkscape site itself here:

If your operating system (e.g. your Linux distro) uses a different default version of Python (or Perl, Ruby, etc.) than what is required by Inkscape extensions, please see Extension Interpreters for how to set the interpreter that Inkscape will use. The most common example of this is that the default Python version of the operating system is 3, but Inkscape requires Python2, resulting in all extensions giving an error.

which leads to this page, which says:

Selecting a specific interpreter version (via preferences file) In the preferences.xml file, a user can set a specific executable of the interpreter that Inkscape should use to execute extensions of a specific type.

This is especially useful, if the system's default version of the interpreter is incompatible with the one used by Inkscape's extension subsystem (e.g. Inkscape extensions that rely on inkex.py will only work with Python 2 (as of Inkscape 0.92.1), while on some recent Linux distributions, the default Python version used is Python 3, which results in errors during execution of extensions).

To change the executable that will be used to run script extensions to a different value than the default value in the above table, you need to do the following:

quit all running Inkscape processes Open your perferences.xml file with a text editor (find the exact location of the file by going to Edit -> Preferences -> System: User Preferences) search the group which holds settings for the extension system itself and options of various extensions:

<group
 id="extensions"
 …
 org.ekips.filter.gears.teeth="24"
 org.ekips.filter.gears.pitch="20"
 org.ekips.filter.gears.angle="20" />

Insert a key for the interpreter, for example 'python-interpreter' for setting the program that should be used to run python extensions, and set the string to the absolute path to the python binary which is compatible with Inkscape's current extension scripts (in the example below, the path is "/usr/bin/python2.7". It will look different on Windows systems.):

<group
 id="extensions"
 python-interpreter="/usr/bin/python2.7"
 …
 org.ekips.filter.gears.teeth="24"
 org.ekips.filter.gears.pitch="20"
 org.ekips.filter.gears.angle="20" />

Save the preferences file, and launch Inkscape to test the extensions.

like image 102
pretzlstyle Avatar answered Nov 04 '22 11:11

pretzlstyle