【发布时间】:2023-03-25 01:23:01
【问题描述】:
我从我的 .py 项目创建了一个 .exe 文件。当我尝试在桌面上保存和输出 .csv 文件时,我得到“错误 13 权限被拒绝”,因为我没有管理员权限。相反,我需要将文件保存到 C:/Users/Public 以使其工作。 那么,每次我收到“错误 13”时,如何使用 Tkinter 制作带有此消息的弹出窗口?错误仅在 cmd 中显示。
## Write output to csv file
def save_file():
path_to_output_file = fd.asksaveasfilename()
if not path_to_output_file:
return
file_count = 1
for rows in range(len(df)):
if rows % 500 == 0:
df[rows:rows+500].to_csv(path_to_output_file + str(file_count) + '.csv', index=False, header=True, quoting=csv.QUOTE_NONNUMERIC)
file_count += 1
【问题讨论】:
-
哪一行导致了错误?完整的错误信息是什么?您应该能够将违规行包含在
try: <line with error> except PermissionError: <code to display popup>中。 -
Tkinter 回调 Traceback 中的异常(最近一次调用最后一次):文件“tkinter_init_.py”,第 1892 行,在 call 文件“目录中Master.py”,第 136 行,在 save_file 文件中“pandas\core\generic.py”,第 3466 行,在 to_csv 文件中“pandas\io\formats\format.py”,第 1105 行,在 to_csv 文件中“pandas\io\格式\csvs.py",第 237 行,保存文件 "pandas\io\common.py",第 702 行,在 get_handle PermissionError: [Errno 13] Permission denied: 'C:/Users/Melleo/Desktop/dm1.csv '
-
第136行,即:
df[rows:rows+500].to_csv(path_to_output_file + str(file_count) + '.csv', index=False, header=True, quoting=csv.QUOTE_NONNUMERIC)
标签: python pandas tkinter permission-denied