import PIL
img = PIL.Image.new("RGB", (100,100))
img.show()
错误消息:
FSPathMakeRef(/Applications/Preview.app)失败,错误为-43。
答案 0 :(得分:1)
在github上有一个针对Pillow 7的官方修复程序,但是我仍然在6上。
这似乎是PIL ImageShow问题,PIL MacViewer使用/Applications/Preview.app
作为OSX Preview应用程序的绝对路径。
卡塔琳娜州不存在。我快速进行了入侵,将ImageShow.py
更改为/Applications/Preview.app
,Preview.app
消失了。在Catalina OSX之前的版本上,这也许行不通,但我没有一种简单的测试方法。
它显然已移至/System/Applications/Preview.app
,因此在运行时快速检查可能会涵盖这两种情况。
elif sys.platform == "darwin":
class MacViewer(Viewer):
format = "PNG"
options = {'compress_level': 1}
preview_locations = ["/System/Applications/Preview.app","/Applications/Preview.app"]
preview_location = None
def get_preview_application(self):
if self.preview_location is None:
for pl in self.preview_locations:
if os.path.exists(pl):
self.preview_location = pl
break
if self.preview_location is None:
raise RuntimeError("Can't find Preview.app in %s" % self.preview_locations)
return self.preview_location
def get_command(self, file, **options):
# on darwin open returns immediately resulting in the temp
# file removal while app is opening
pa = self.get_preview_application()
command = "open -a %s" % pa
command = "(%s %s; sleep 20; rm -f %s)&" % (command, quote(file),
quote(file))
return command
def show_file(self, file, **options):
"""Display given file"""
pa = self.get_preview_application()
fd, path = tempfile.mkstemp()
with os.fdopen(fd, 'w') as f:
f.write(file)
with open(path, "r") as f:
subprocess.Popen([
'im=$(cat);'
'open %s $im;'
'sleep 20;'
'rm -f $im' % pa
], shell=True, stdin=f)
os.remove(path)
return 1
答案 1 :(得分:0)
从Sean True's answer开始,一个更快但临时的解决方法是简单地在旧位置建立一个指向Preview.app的符号链接。在终端运行
ln -s /System/Applications/Preview.app /Applications/Preview.app
这为我解决了这个问题。