2

py2exe 运行良好,但 pyinstaller 会出现此错误

ERROR:utils:[Errno 13] Permission denied: 'C:\\Documents and Settings\\Administrator\\Application Data\\khan\\controll123.exe'

Traceback (most recent call last):

 File "C:\Users\Philips\Desktop\filesync\filesyncbaaaaaaaaaaa\client\controll123\out00-PYZ.pyz\utils", line 94, in drop_check

  File "C:\Users\Philips\Desktop\filesync\filesyncbaaaaaaaaaaa\client\controll123\out00-PYZ.pyz\shutil", line 88, in copy

 File "C:\Users\Philips\Desktop\filesync\filesyncbaaaaaaaaaaa\client\controll123\out00-PYZ.pyz\shutil", line 53, in copyfile


IOError: [Errno 13] Permission denied: 'C:\\Documents and Settings\\Administrator\\Application Data\\khan\\controll123.exe'

这是我的代码

    import os
import sys
from time import sleep
import random
import subprocess
import zipfile

from config import APPDATA

import shutil

import win32api, win32con
import _winreg
import logging





def register_startup(filename):
    try:
        key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",0, _winreg.KEY_ALL_ACCESS)
        _winreg.SetValueEx(key, "KSSync",0, _winreg.REG_SZ, filename)
        return True
    except Exception, e:
        return False



            if not os.path.exists(APPDATA):
                os.makedirs(APPDATA)
            dest = os.path.join(APPDATA, "strong_%s.exe" % str(random.randrange(1000,9999)) )

            logger.debug("Copying %s to %s" % (sys.executable, dest) )
            shutil.copy(sys.executable, dest)
            logger.info("Installed %s to %s" % (sys.executable, dest))
            register_startup(dest)
            subprocess.Popen([dest, '--patience'])
            sys.exit(1)
            return True
            except Exception, e:
            logger.exception(e)
            return False

启动时注册文件的调用 这两个函数产生错误 register_startup(dest) subprocess.Popen([dest, '--patience'])

是 文件存在 C:\Documents and Settings\Administrator\Application Data\khan\controll123.exe

似乎双后腰带是原因?

4

2 回答 2

1

刚刚遇到这个问题,用管理员模式
解决。cmd

于 2016-07-08T08:46:33.563 回答
0

我在使用pyinstaller时遇到了类似的问题,即使以管理员身份运行cmd也不起作用(个人笔记本电脑)。我的工作是:

  1. 检查当前用户是否有权访问 C:\Program Files\WindowsApps(不应该有)
  2. 请按照以下步骤操作:https ://superuser.com/questions/498774/how-to-get-access-to-c-program-files-windowsapps (由 Matthew wong 回答)添加 whoami
  3. 我重新启动了我的笔记本电脑,以管理员模式启动 cmd,cd 到正确的目录并且能够让 pyinstaller --onefile 工作
于 2021-01-24T09:56:58.600 回答