在 Python 中使用 pyx.canvas.writeGSfile() 时如何修复 'FileNotFoundError'?

How to fix 'FileNotFoundError' when using pyx.canvas.writeGSfile() in Python?

我想使用 Pyx 模块生成 jpeg 或 png 文件。我发现 pyx.canvas.writeGSfile() 我尝试在以下代码中使用:

from pyx import *


def mark(x, y):
    return path.circle(x, y, 0.1)


if __name__ == '__main__':
    c = canvas.canvas()
    # r = 70
    f = trafo.scale(0.7, 1)

    circle = path.circle(0, 0, 2)
    a, b = circle.split([0, 2])
    c.stroke(a, [style.linewidth.Thick, f])
    d1 = f.apply(*circle.at(0.5*circle.arclen()))
    d2 = f.apply(*circle.at(circle.arclen()))
    c.fill(mark(*d1))
    c.fill(mark(*d2))
    c.writeGSfile('test.jpeg')

但它返回以下错误:

Traceback (most recent call last):
  File "/Python/pyx/test.py", line 19, in <module>
    c.writeGSfile('test.png')
  File "\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyx\canvas.py", line 474, in writeGSfile
    p = config.Popen(cmd, stdin=config.PIPE)
  File "\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyx\config.py", line 218, in Popen
    return subprocess.Popen(cmd, *args, **kwargs)
  File "\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 997, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

我尝试调试,但无法理解 processing.py 部分。有什么想法吗?

您需要安装 ghostscript (gs) 才能生成位图输出。