Access denied using Py2exe

后端 未结 4 1126
后悔当初
后悔当初 2021-01-11 17:52

I\'m using Py2exe to create an executable as a windows service.

When I run the script I get this error:

File \"C:\\TeamCity\\buildAgent\\work\

4条回答
  •  粉色の甜心
    2021-01-11 18:16

    The problem is likely an antivirus program blocking write access to .exe files as others have noted. If you cannot or do not want to disable antivirus the following patch at the beginning of your setup.py file will rename the file to avoid the .exe extension before the modification and rename it back after.

    import py2exe.py2exe_util
    from py2exe.py2exe_util import add_resource
    import os
    
    def add_resource_patch(name, *arg, **kwarg):
        name_tmp = name + '.tmp'
        os.rename(name, name_tmp)
        add_resource(name_tmp, *arg, **kwarg)
        os.rename(name_tmp, name)
    
    py2exe.py2exe_util.add_resource = add_resource_patch
    
    from distutils.core import setup
    import py2exe
    setup(...)
    

提交回复
热议问题