Inkscape and textext: Deprecation Warning

by Pascal Schulthess

I just came across the following error of textext in Inkscape.

~/.inkscape/extensions/textext.py:55: DeprecationWarning: 
the md5 module is deprecated; use hashlib instead
import os, sys, tempfile, traceback, glob, re, md5, copy

This error arises for textext 0.4.4., Inkscape 0.46 and Python 2.6.2. Fortunately I found a solution at bitbucket. But since I had some problems understanding how to change the python file, I will help you out with a detailed how-to.

Open the textext.py file mentioned in the error message with an editor of your choice. Now change the the lines

54
55
56
import inkex
import os, sys, tempfile, traceback, glob, re, md5, copy
from lxml import etree

into

54
55
56
57
import inkex
import os, sys, tempfile, traceback, glob, re, copy
import hashlib
from lxml import etree

Furthermore change

868
869
870
871
872
873
874
875
876
877
878
    def __init__(self, document):
        PdfConverterBase.__init__(self, document)
        self.hash = None
 
    def convert(self, *a, **kw):
        # compute hash for generating unique ids for sub-elements
        self.hash = md5.new('%s%s' % (a, kw)).hexdigest()[:8]
        return PdfConverterBase.convert(self, *a, **kw)
 
    def pdf_to_svg(self):
        exec_command(['pdf2svg', self.tmp('pdf'), self.tmp('svg'), '1'])

into

868
869
870
871
872
873
874
875
876
877
878
879
880
881
    def __init__(self, document):
        PdfConverterBase.__init__(self, document)
        self.hash = None
        USE_GTK = False
 
    def convert(self, *a, **kw):
        # compute hash for generating unique ids for sub-elements
        m = hashlib.md5()
        m.update('%s%s' % (a, kw))
        self.hash = m.hexdigest()[:8]
        return PdfConverterBase.convert(self, *a, **kw)
 
    def pdf_to_svg(self):
        exec_command(['pdf2svg', self.tmp('pdf'), self.tmp('svg'), '1'])

That’s it. Restart Inkscape and you’re done.

Happy TeXing