שלום
כתבתי תוכנה שפותחת קבצי RAR.
השתמשתי בunrar.
כשניסיתי להריץ בPYCHARM, קיבלתי את השגיאה הבאה
"LookupError: Couldn't find path to unrar library."
בחיפושים בגוגל ראיתי שמה שצריך לעשות זה להוסיף environment variable כדי שזה יעבוד, וזה עבד.
הבעיה היתה כשהמרתי את זה לEXE וניסיתי לפתוח את הקובץ קיבלתי חלונית
מישהו יודע מה הפתרון?
תודה רבה
הקוד:
from unrar import rarfile
from tkinter import *
from tkinter import filedialog
from tkinter import messagebox
def get_path():
source_file_path = source_path_entry.get()
destination_file_path = destination_path_entry.get()
return source_file_path, destination_file_path
def check_path():
source_file_path = source_path_entry.get()
destination_file_path = destination_path_entry.get()
start_path = source_file_path[:3]
if source_file_path[:-4:-1] == "rar" and destination_file_path[:3] == start_path:
unrar()
elif source_file_path[:-4:-1] != "rar":
messagebox.showerror(title="invalid path!",
message="The file you choose is incorrect. \n Try again!")
elif destination_file_path[:3] != start_path:
messagebox.showerror(title="invalid path!",
message="The destination path you entered is incorrect. \n Try again!")
else:
print("error")
def unrar():
try:
rar = rarfile.RarFile(get_path()[0])
members = rar.namelist()
for i in members:
rar.extractall(members=i, path=get_path()[1])
end_label = Label(root, text="Successfully completed!", fg="#00ff00")
end_label.pack()
except Exception as e:
# print(e)
except_label = Label(root, text=e, fg="#ff0000")
except_label.pack()
def get_file_path():
file_path = filedialog.askopenfilename()
source_path_entry.delete(0, last=len(source_path_entry.get()))
source_path_entry.insert(0, file_path)
source_path_entry.config(fg="#000000", width=len(source_path_entry.get()))
def get_destination_path():
destination_path = filedialog.askdirectory()
destination_path_entry.delete(0, last=len(destination_path_entry.get()))
destination_path_entry.insert(0, destination_path)
destination_path_entry.config(fg="#000000", width=len(destination_path_entry.get()))
root = Tk()
root.geometry("400x400")
root.title("unrar files")
head_label = Label(root, text="welcome to unrar files!", font="ariel", fg="#000000", pady=10)
head_label.pack()
source_path_entry = Entry(root)
source_path_entry.pack()
source_path_entry.config(fg="#d4d4d4")
source_path_entry.insert(0, "enter rar file path")
or_label = Label(root, text="OR:", pady=10)
or_label.pack()
choose_file_button = Button(root, text="choose file", command=get_file_path)
choose_file_button.pack()
destination_path_entry = Entry(root)
destination_path_entry.pack()
destination_path_entry.insert(0, "enter destination file path")
destination_path_entry.config(fg="#d4d4d4", width=len(destination_path_entry.get()))
choose_destination_button = Button(root, text="choose destination", command=get_destination_path)
choose_destination_button.pack()
unrar_button = Button(root, text="unrar", command=check_path)
unrar_button.pack()
root.mainloop()

