【问题标题】:Changing the Python interpreter for Inkscape更改 Inkscape 的 Python 解释器
【发布时间】:2019-02-02 10:28:37
【问题描述】:

我在使用 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

最后一行似乎正是我所说的——通常这个错误是由使用 python 3 解释器运行 python 2 代码引起的,并且可以通过简单地将字符串对象 str 传递为 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

这似乎又是一个明显的 2 对 3 错误。

有没有办法改变 Inkscape 使用的 python 解释器?

【问题讨论】:

    标签: python inkscape


    【解决方案1】:

    我实际上从 Inkscape 网站本身here找到了我的问题的答案:

    如果您的操作系统(例如您的 Linux 发行版)使用的 Python(或 Perl、Ruby 等)的默认版本与 Inkscape 扩展所需的不同,请参阅扩展解释器了解如何设置 Inkscape 将使用的解释器采用。最常见的例子是操作系统的默认 Python 版本是 3,但 Inkscape 需要 Python2,导致所有扩展都报错。

    leads to this page,上面写着:

    选择特定的解释器版本(通过首选项文件)在 在preferences.xml 文件中,用户可以设置特定的可执行文件 Inkscape 应该用来执行扩展的解释器 具体类型。

    这特别有用,如果系统的默认版本 解释器与 Inkscape 扩展使用的解释器不兼容 子系统(例如,依赖于 inkex.py 的 Inkscape 扩展只会 使用 Python 2(从 Inkscape 0.92.1 开始),而在最近的一些 Linux 上 发行版,使用的默认 Python 版本是 Python 3, 导致执行扩展时出错)。

    将用于运行脚本扩展的可执行文件更改为 与上表中的默认值不同的值,您需要 执行以下操作:

    退出所有正在运行的 Inkscape 进程 打开您的 perferences.xml 文件 使用文本编辑器(通过转到 编辑->首选项->系统:用户首选项)搜索组 它包含扩展系统本身的设置和选项 各种扩展:

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

    为解释器插入一个键,例如'python-interpreter' 设置应该用于运行 python 扩展的程序,以及 将字符串设置为 python 二进制文件的绝对路径,即 与 Inkscape 当前的扩展脚本兼容(在示例中 下面,路径是“/usr/bin/python2.7”。它看起来会有所不同 Windows 系统。):

    <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 以测试扩展。

    【讨论】:

    • 记得在 Inkscape 关闭时编辑首选项文件,否则它将被覆盖,您将丢失所做的更改
    • 我改成了python-interpreter="/usr/bin/python3.7。语法错误消失了,但是当我点击“应用”时,什么也没发生。没有弹出错误,也没有生成 gcode 文件。
    • 我解决了。对我来说是/home/username/anaconda3/bin/python。我去view&gt;messages查看日志并点击capture log messages。然后我找到了问题的原因。
    【解决方案2】:

    你的回答对我有帮助。但我走了另一条路。使用pyenv local 2.7.18.config/inkscape/extension 文件夹中设置本地python。使用它安装所需的任何 python 依赖项并且它工作正常。

    更改 python 解释器的设置对我不起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-06
      • 1970-01-01
      • 2012-07-04
      • 1970-01-01
      • 2023-01-05
      • 2018-11-29
      • 2011-05-29
      • 1970-01-01
      相关资源
      最近更新 更多