转换为exe文件shutil python后,无法复制文件

发布于 2025-01-24 06:21:50 字数 648 浏览 1 评论 0原文

我一直在尝试复制用于启动文件夹的Python脚本。一切都可以正常工作,但是在将脚本编译到.exe文件中后,我总是会遇到此错误:

File "shutil.py", line 417, in copy
  File "shutil.py", line 254, in copyfile
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\x\\AppData\\Local\\Temp\\_MEI187322\\script.exe'

这是代码:

pathFile = os.path.join("C:\\", "Users", os.getlogin(), "AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup", "script.exe")

pathCurrent = os.path.realpath(__file__)

if pathCurrent != pathFile:
    try:
        shutil.copy(pathCurrent, pathFile)
    except shutil.SameFileError:
        pass

else:
    pass

I've been trying to copy python script, that I use to startup folder. Everything works as it should, BUT after I compile the script into .exe file, I always get this error:

File "shutil.py", line 417, in copy
  File "shutil.py", line 254, in copyfile
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\x\\AppData\\Local\\Temp\\_MEI187322\\script.exe'

This is the code:

pathFile = os.path.join("C:\\", "Users", os.getlogin(), "AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup", "script.exe")

pathCurrent = os.path.realpath(__file__)

if pathCurrent != pathFile:
    try:
        shutil.copy(pathCurrent, pathFile)
    except shutil.SameFileError:
        pass

else:
    pass

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文