12
votes

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\582d895bd5b431ac\winpython\WinPython-32bit-2.7.3.3\python-2.7.3\lib\site-packages\py2exe\build_exe.py", line 860, in build_executable add_resource(ensure_unicode(exe_path), script_bytes, u"PYTHONSCRIPT", 1, True) RuntimeError: EndUpdateResource: Access is denied.

This is the call to py2exe:

    setup(
    name = NAME,
    description = DESCRIPTION,
    version = '1.0.133.43',
    service = [{'modules':["ServiceLauncher"], 'cmdline':'pywin32'}],
    zipfile=None,
    options = {
        "py2exe":{"packages":"encodings",
                  "includes":"win32com,win32service,win32serviceutil,win32event",
                  "excludes":"libiomp5md.dll"
        },
        },
    )

The problem occurs only on the build machine, it runs fine on my dev pc.

I've tried to set Full Control to everyone on the work folder, but it doesn't work.

Any idea?

Thank you.

4
Out of curiosity, try a shorter path-name if possible. Weird bugs can occur when the path is to long in Windows.Torxed
The error might not be access to a particular file on the filesystem, but to some other feature, like a registry key or a service manager setting (since I notice you're using ServiceLauncher, win32service, etc.…). Are you running as admin?abarnert
I'm running as Administrator. I've tried a shorter path with no luck...Be.St.
How can I check if it is a problem related to registry or service manager?Be.St.
Could check your AUTH log in the "Event Viewer", might get lucky.Torxed

4 Answers

38
votes

After two days investigating we found a solution with the help of the IT staff.

The issue arise when py2exe try to modify the executable adding metadata and\or icon.

The root cause? Simple... ANTIVIRUS.

It considers that operation a threat and cause the Access Denied error.

Thank you all!

2
votes

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(...)
1
votes

I found that disconnecting from the Internet was enough to solve the problem (though this is probably related to the disabling the antivirus solution proposed).

0
votes

another possible solution is that you already have a dist folder with files in it - i did (forgot i had already run py2exe). removed the folder and it worked again