首页 > 解决方案 > 如果我运行 .exe,则无法写入文件

问题描述

我正在编写一个简短的程序,我想将一个充满街道名称的数组写入 .txt 文件。Everyting 工作正常,但如果我使用 pyinstaller 将 python 代码转换为 .exe,我将无法再写入新的 .txt 文件。为什么会这样?

    with open(f"C:\\Users\\auser\\Desktop\\tset\\{txtname}.txt", "a") as txt_file:
        for line in new_addresses:
            txt_file.write(line + "\n")

    txt_file.close()

这就是我创建.exe的方式:

pyinstaller --onefile street.py

回溯(最后一次调用):文件“streets.py”,第 65 行,在 PermissionError:[Errno 13] 权限被拒绝:'C:\Users\auser\Desktop\tset\test.txt' [7048] 无法执行脚本重写字

标签: pythonpyinstaller

解决方案


我现在开始工作了。我的防病毒程序由于某种原因阻止了执行。


推荐阅读