使用Inkscape时,我不断收到错误消息,似乎暗示没有满足python 2 vs 3的期望,尽管我都安装了它们。例如,当我尝试制作从模板生成的新文档时,我得到了,
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
Run Code Online (Sandbox Code Playgroud)
最后一行似乎正是我所说的-通常此错误是由使用python 3解释器运行python 2代码引起的,并且可以通过简单地将字符串对象str as str.decode()或其他形式传递来解决。但是,显然,编辑inkscape源代码不是理想的解决方案。
此外,当尝试生成Voronoi图时,我得到
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
Run Code Online (Sandbox Code Playgroud)
这似乎又是一个明显的2 vs. 3错误。
有没有办法改变Inkscape使用的python解释器?
Ano*_*ous 11
其实,我找到了答案,从Inkscape的网站本身我的问题在这里:
如果您的操作系统(例如Linux发行版)使用的默认Python版本(或Perl,Ruby等)与Inkscape扩展所要求的版本不同,请参阅扩展解释器以了解如何设置Inkscape将使用的解释器。最常见的例子是操作系统的默认Python版本是3,但是Inkscape需要Python2,导致所有扩展都给出错误。
这导致该页面,其中说:
选择特定的解释器版本(通过首选项文件)在preferences.xml文件中,用户可以设置Inkscape用于执行特定类型的扩展名的解释器的特定可执行文件。
如果系统的默认解释器版本与Inkscape扩展子系统使用的版本不兼容(例如,依赖于inkex.py的Inkscape扩展仅适用于Python 2(自Inkscape 0.92.1起)),则此功能特别有用。在一些最新的Linux发行版中,使用的默认Python版本是Python 3,这会在扩展执行期间导致错误)。
要将用于运行脚本扩展的可执行文件更改为与上表中的默认值不同的值,您需要执行以下操作:
退出所有正在运行的Inkscape进程,使用文本编辑器打开perferences.xml文件(通过转到“编辑”->“首选项”->“系统:用户首选项”来查找文件的确切位置),搜索包含扩展系统本身和选项设置的组各种扩展名:
Run Code Online (Sandbox Code Playgroud)<group id="extensions" … org.ekips.filter.gears.teeth="24" org.ekips.filter.gears.pitch="20" org.ekips.filter.gears.angle="20" />插入解释程序的键,例如“ python-interpreter”,以设置应用于运行python扩展程序的程序,并将字符串设置为与Inkscape当前扩展脚本兼容的python二进制文件的绝对路径(在在下面的示例中,路径为“ /usr/bin/python2.7”。在Windows系统上,它看起来会有所不同。):
Run Code Online (Sandbox Code Playgroud)<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" />保存首选项文件,然后启动Inkscape来测试扩展。