如何解决py2app / PIL问题导致MacOS崩溃以在其他计算机上注销
这基本上是一个桌面应用程序,用于获取区域屏幕截图并以递增的数字文件名保存到选定的文件夹。没什么,只使用PIL和Tkinter库。
- 如果我从开发中运行py或应用文件,一切都很好 机器。
- 在没有lib append的任何其他计算机上运行.py文件会导致找不到PIL模块 IDE上发生错误。
- 以任何方式运行.app都会使应用程序退出登录 屏幕。
我已经尝试了几种方法来解决该问题;例如--includes = PIL,添加打包信息选项,将实际的库文件添加到.app库文件文件夹,附加库路径
在过去的两天里,我一直在努力解决这个问题,我感觉自己像是在兜圈子,在这个问题上没有什么优先事项可以解决。
这是文件。
谢谢
main.py
import sys
sys.path.append("lib/python3.8/") # latest attempt to show PIL files.
import tkinter as tk
from tkinter import filedialog,simpledialog
from tkinter import ttk
from PIL import ImageTk,ImageGrab,ImageEnhance
# if platform() == 'Darwin': # How Mac OS X is identified by Python
# system('''/usr/bin/osascript -e 'tell app "Finder" to set frontmost of process "Python" to true' ''')
# subprocess.call(["/usr/bin/osascript","-e",'tell app "Finder" to set frontmost of process "Python" to true'])
root = tk.Tk()
root.resizable(0,0)
root.geometry("210x400+0+0")
root.title("Erkan Ulu Crop Aracı")
root.iconbitmap("bitmap.ico")
root.configure(bg="#1F2020")
# logo = tk.PhotoImage(file="app-logo.png")
logo = tk.PhotoImage(file="appicon.png")
# Theme Options
path_to_theme = "./awthemes-9.4.2/"
root.tk.call('lappend','auto_path',path_to_theme)
root.tk.call('package','require','awdark')
style = ttk.Style()
style.theme_use("awdark")
# Label Config
style.configure("TLabel",padding=(10,10,10),justify=tk.CENTER,font="Open-sans 10")
# Button Config
style.configure("TButton",width=20,font="Open-sans 10 bold")
folderPath = tk.StringVar()
folderPath_View = tk.StringVar(value="Başlamadan Önce\nLütfen Klasör Seçiniz.")
file_name = 1
question_no = tk.StringVar(value="1")
question_text = tk.StringVar(value="Çekilen Soru No: ")
default_path = "~/Desktop"
def set_file_name():
global file_name
file_name = simpledialog.askinteger("Soru No:","Başlanacak soru numarasını yazınız.",parent=root)
question_no.set(file_name)
print("Sayı numarası ayarlandı")
# def set_pre_file_name():
# global file_name
# file_name = simpledialog.askinteger("Soru Öncesi İsim","Soru İsminin Başına Yazılaca ",parent=root)
# question_no.set(file_name)
# print("Soru Öncesi İsim Ayarlandı")
def undo_image(event):
global file_name
file_name -= 1
area_sel(event)
print("Görsel tekrar çekiliyor")
def reset(event):
global file_name
file_name = 1
print("Sıfırlandı")
return file_name
def set_folder_name():
folder_selected = filedialog.askdirectory(initialdir="~/Desktop")
folderPath.set(folder_selected)
view_path = str(folder_selected)
X_path = view_path.rsplit("/",1)[1]
folderPath_View.set(X_path)
root.update()
global file_name
file_name = 1
question_no.set(file_name)
print("Klasör Ayarlandı: " + folder_selected)
def area_sel(event):
x1 = y1 = x2 = y2 = 0
roi_image = None
def on_mouse_down(event):
nonlocal x1,y1
x1,y1 = event.x,event.y
canvas.create_rectangle(x1,y1,x1,outline='red',tag='roi')
def on_mouse_move(event):
nonlocal roi_image,x2,y2
x2,y2 = event.x,event.y
canvas.delete('roi-image') # remove old overlay image
roi_image = image.crop((x1,y2)) # get the image of selected region
canvas.image = ImageTk.PhotoImage(roi_image)
canvas.create_image(x1,image=canvas.image,tag=('roi-image'),anchor='nw')
canvas.coords('roi',y2)
# make sure the select rectangle is on top of the overlay image
canvas.lift('roi')
root.withdraw()
image = ImageGrab.grab()
bgimage = ImageEnhance.Brightness(image).enhance(0.25)
win = tk.Toplevel()
win.attributes('-fullscreen',1)
win.attributes('-topmost',1)
canvas = tk.Canvas(win,highlightthickness=0)
canvas.pack(fill='both',expand=1)
tkimage = ImageTk.PhotoImage(bgimage)
canvas.create_image(0,image=tkimage,anchor='nw',tag='images')
win.bind('<ButtonPress-1>',on_mouse_down)
win.bind('<B1-Motion>',on_mouse_move)
win.bind('<ButtonRelease-1>',lambda e: win.destroy())
win.bind('<Escape>',lambda e: win.destroy())
win.focus_force()
win.grab_set()
win.wait_window(win)
root.deiconify()
if roi_image:
global file_name
folder_name = folderPath.get()
# folder_name = "/Users/anil/Desktop/testfolder"
convert_img = roi_image.convert("RGB")
save_path = folder_name + "/" + str(file_name) + ".jpeg"
file_name += 1
question_no.set(file_name)
save_format = "JPEG"
convert_img.save(save_path,save_format)
# show_image(convert_img,file_name-1)
# root.focus_force()
# root.focus_set()
# root.mainloop()
print("Soru Çekildi")
root.update() # new_image_question()
#PADDING = (SOLA,YUKARI,SAĞA,AŞAĞI)
ttk.Label(root,image=logo).pack()
ttk.Button(root,text="Klasör Seç\nBaşla",command=set_folder_name).pack()
ttk.Label(root,textvariable=folderPath_View,font="Open-sans 12",padding=(0,20)).pack()
ttk.Button(root,text="Başlanacak Soru\nNumarasını Seç",command=set_file_name).pack()
ttk.Label(root,text="Çekilecek Soru No:",0)).pack()
ttk.Label(root,textvariable=question_no,0),font="Open-sans 12").pack()
ttk.Label(root,text="Soru Ekle = S Tuşu\nSoruyu Tekrar Çek = T Tuşu").pack()
root.bind('<Key-s>',area_sel)
root.bind('<Key-t>',undo_image)
root.bind('<Key-Escape>',reset)
root.mainloop()
setup.py
"""
This is a setup.py script generated by py2applet
Usage:
python setup.py py2app
"""
from setuptools import setup
APP = ['main.py']
DATA_FILES = ["logo.png","bitmap.ico","awthemes-9.4.2","appicon.icns","appicon.png"]
OPTIONS = {
'iconfile':'appicon.icns','argv_emulation': True,'site_packages': True,'use_pythonpath': True,'packages': ['PIL','tkinter'],'includes': ['PIL','tkinter','ImageTk']
}
setup(
app=APP,data_files=DATA_FILES,version="1",name="Crop Tool",options={'py2app': OPTIONS},setup_requires=['py2app'],install_requires=["Pillow"]
)
编译错误:
Modules not found (unconditional imports):
* PyQt5.QBuffer (PyQt5.QtCore,PyQt5.QtGui)
* PyQt5.QIODevice (PyQt5.QtCore,PyQt5.QtGui)
* PySide2.QBuffer (PySide2.QtCore,PySide2.QtGui)
* PySide2.QIODevice (PySide2.QtCore,PySide2.QtGui)
* _gdbm (dbm.gnu)
* _overlapped (asyncio.windows_events)
* cffi (PIL.Image,PIL.PyAccess)
* cffi.FFI (PIL.Image)
* com (com.sun.jna)
* com.jna (com.sun)
* com.sun (com.sun.jna.platform)
* numpy (PIL.ImageFilter)
* olefile (PIL.FpxImagePlugin,PIL.MicImagePlugin)
* ordereddict (pkg_resources._vendor.pyparsing)
* win32com (win32com)
* win32com.shell (win32com.shell)
* win32com.shellcon (win32com.shell)
Modules not found (conditional imports):
* Image (/Users/anil/PycharmProjects/ULUCrop-V2/venv/lib/python3.8/site-packages/py2app/recipes/PIL/prescript.py)
* PySide2 (PIL.ImageQt)
* PySide2.QtGui (PIL.ImageQt)
* StringIO (pkg_resources._vendor.six)
* cffi (PIL.ImageTk)
* com (pkg_resources._vendor.appdirs)
* com.sun.jna (pkg_resources._vendor.appdirs)
* com.sun.jna.platform (pkg_resources._vendor.appdirs)
* win32com (pkg_resources._vendor.appdirs)
* win32com.shell (pkg_resources._vendor.appdirs)
解决方法
Modules not found
-消息大多是无害的。
根据您的描述(在您的开发机器上一切正常,其中安装了所有库,但在没有库的另一台计算机上无法正常工作)似乎您正在使用带有选项 -A
或 {{1} 的 py2app }(即--alias
),从而创建不包含库的开发版本(请参阅py2app Option Reference)。如果是这种情况,请删除 python setup.py py2app -A
选项并仅使用
-A
生成一个包含所有库的 .app。
如果您不使用 python setup.py py2app
选项并且仍然收到有关缺少库的错误消息,请复制并粘贴完整的错误消息;它可能包含额外信息,以便为您提供进一步帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。