R. Kap
R. Kap

Reputation: 619

Python <`No such file or directory: 'gs'> error *UPDATE*

I have implemented the following save function in my program which allows the user to save as a JPEG file whatever he/she draws on the Tkinter canvas with the Turtle. How it is supposed to work is that it first captures the screen and Tkinter canvas and then creates a postscript file based on it. Then it converts that postscript file as a PIL (Python Imaging Library) readable file type, and then the PIL saves the converted file as a JPEG. My save function is shown below:

def savefirst(): 
    # Capture screen and Tkinter canvas
    cnv = getscreen().getcanvas() 
    global hen
    # Save screen and canvas as Postscript file
    ps = cnv.postscript(colormode = 'color')
    # Open a Tkinter file dialog that allows to input his.her own name for the file
    hen = filedialog.asksaveasfilename(defaultextension = '.jpg')
    # Convert Postscript file to PIL readable format
    im = Image.open(io.BytesIO(ps.encode('utf-8')))
    # Finally save converted file as a JPEG
    im.save(hen + '.jpg')

However, whenever I run this save function, I get the error shown below:

line 2396, in savefirst
    im.save(hen + '.jpg')
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/PIL/Image.py", line 1646, in save
    self.load()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/PIL/EpsImagePlugin.py", line 337, in load
    self.im = Ghostscript(self.tile, self.size, self.fp, scale)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/PIL/EpsImagePlugin.py", line 143, in Ghostscript
    stdout=subprocess.PIPE)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 950, in __init__
    restore_signals, start_new_session)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 1544, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'gs'

What is 'gs', why is this happening, and how would I fix the issue causing this error?

FYI: Just in case you need to know, my operating system is Macintosh and my Python version is 3.5.1

EDIT: Apparently, just as I thought, 'gs' means GhostScript, and that error was occurring because I had to install it (Thanks to the answer for making me realize that). I have installed the .dmg from here, but I still keep on getting the error. Maybe it has something to do with my current OS (Mac OS 10.11.2)? Or something else is wrong with my save function? I honestly do not know. Anyways, why does this error keep on occurring even though I have (hopefully) installed GhostScript? Again, any help is very much appreciated!

Upvotes: 0

Views: 1226

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799160

PIL delegates PostScript file creation to GhostScript, which is not installed on your system. Install it.

Upvotes: 2

Related Questions