python-3.xpyx

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


I would like to generate a jpeg or png file using the Pyx module. I found pyx.canvas.writeGSfile() which I tried to use in the following code:

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')

But it spits back the following error:

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

I tried to debug but I'm having trouble understanding the processing.py section. Any ideas?


Solution

  • You need to have ghostscript installed (gs) to generate bitmap output.