You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用PyInstaller打包app.py为单文件时遇PermissionError权限错误

问题

执行命令 pyinstaller app.py --onefile 将app.py打包为单文件可执行程序时,出现权限错误:

14907 WARNING: Execution of 'copyfile' failed on attempt #1 / 20: PermissionError(13, 'Permission denied').
RuntimeError: Execution of 'copyfile' failed - no more attempts left!

用于鼠标键盘控制的代码如下:

import pyautogui
import time

pyautogui.hotkey("win", "r")
pyautogui.write("notepad")
pyautogui.hotkey("enter")
time.sleep(1)
pyautogui.moveTo(500, 300, 1)
pyautogui.write("Hello World!", .500)
pyautogui.press("t", 2, 1)
pyautogui.press("e", 2, 1)
pyautogui.press("s", 2, 1)
pyautogui.press("t", 2, 1)
解决方案
  • 以管理员身份运行命令行:右键命令提示符或终端,选择“以管理员身份运行”后再执行打包命令。权限不足是这类错误的常见诱因,管理员权限可让PyInstaller顺利完成文件复制操作。
  • 释放目标文件占用:检查打包生成的dist文件夹、临时目录里是否有正在运行的同名可执行文件,或是杀毒软件、文件管理器锁定了相关文件,关闭后重新打包。
  • 更换打包输出目录:默认打包输出在当前目录,可指定非系统盘的自定义目录,比如执行 pyinstaller app.py --onefile --distpath D:\py_pack,规避系统目录的权限限制。
  • 清理PyInstaller缓存:删除当前目录下的build、dist文件夹和app.spec文件,重新执行打包命令,缓存文件损坏也可能导致复制失败。

内容的提问来源于stack exchange,提问作者ecc

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 02:24:55