My program implements the following save function, which allows the user to save as a JPEG file everything that he / she draws on the Tkinter canvas using Turtle. How this should work is that it first captures the screen and the Tkinter canvas, and then creates a postscript on it. It then converts this postscript file to PIL (Python Imaging Library) format, and then PIL saves the converted file in JPEG format. 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 following error:
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'
GhostScript! , . , , Terminal:
`pip install ghostscript`
, :
`conda install --channel https://conda.anaconda.org/mlgill ghostscript`
3 GhostScript - . ?
FYI: , - Mac OS 10.11.2, Python - 3.5.1.
: , , Homebrew. , , ( Homebrew). , , brew install ghostscript. , GhostScript (, , Homebrew). brew doctor , ! **** Gasp **** , , ! , , , brew link ghostscript. , , , ... , , IDLE ! , gs :
dyld: Library not loaded: /opt/X11/lib/libXt.6.dylib
Referenced from: //anaconda/bin/gs
Reason: image not found
Trace/BPT trap: 5
STILL ? Python ( Terminal) gs?
EDIT # 2: , GhostScript Homebrew. , , xQuarts, , -, GhostScript. , STILL ! gs :
:~ #######$ gs
GPL Ghostscript 9.18 (2015-10-05)
Copyright (C) 2015 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
STILL Python, , GhostScript! IDLE , :
FileNotFoundError: [Errno 2] No such file or directory: 'gs'
- ?
№ 3: Python script, , .
- # 4 -
№ 5: , , . , brew doctor , , , - . , , :
Warning: Python is installed at /Library/Frameworks/Python.framework
Homebrew only supports building against the System-provided Python or a
brewed Python. In particular, Pythons installed to /Library can interfere
with other software installs.
, , ? , ?
№ 6: -, ( Mac), ! STILL , savefirst():
line 2395, 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'
, gs :
x=subprocess.Popen(['/usr/local/bin/gs', '--version'], stdout=subprocess.PIPE)
print(x.stdout.read())
Python IDLE. - Python Imaging Library (PIL) gs (, - subprocess.Popen()?). ? xQuarts, GhostScript PIL, Macintosh, savefirst()! ?
P.S. Macintosh (OS 10.11.2), , Macintosh!
- # 7 -
№ 8: , - (,...) /usr/local/bin/gs PATH ( ):
Library/usr/local/bin/gs:/Library/Frameworks/Python.framework/Versions/3.5/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin://anaconda/bin:/Users/Rohan/anaconda/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
, pico ~MyName/.bash_profile :
PATH="Library/usr/local/bin/gs:${PATH}"
export PATH
/.bash.profile. , FileNotFoundError Python! /usr/local/bin/gs PATH ? , Python Imaging Library STILL gs??
№ 9: ! ! . , , - /usr/local/bin/gs Mac Path , , PYTHONPATH, :
os.environ["PATH"] += ":/usr/local/bin:/usr/local/bin/gs"
! ! PIL gs JPEG, , . , , , , JPEG ( @Copperfield!):)