14

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.

Be.St.
  • 4,101
  • 3
  • 25
  • 35
  • Out of curiosity, try a shorter path-name if possible. Weird bugs can occur when the path is to long in Windows. – Torxed Feb 18 '14 at 08:32
  • 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 Feb 18 '14 at 08:37
  • I'm running as Administrator. I've tried a shorter path with no luck... – Be.St. Feb 18 '14 at 08:45
  • How can I check if it is a problem related to registry or service manager? – Be.St. Feb 18 '14 at 08:56
  • Could check your AUTH log in the "Event Viewer", might get lucky. – Torxed Feb 18 '14 at 09:12
  • No luck with the event viewer... – Be.St. Feb 18 '14 at 09:20
  • The simple approach is then to just remove one `includes` at a time, and see whichever fails first. Just to narrow things down. – Torxed Feb 18 '14 at 09:29
  • I've tried removing the includes, adding only one at a time. Also removed packages and exclude. Same error! – Be.St. Feb 18 '14 at 09:33

5 Answers5

40

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!

Be.St.
  • 4,101
  • 3
  • 25
  • 35
  • Thanks for answering this. I had the same problem, googled it, came across this answer, disabled antivirus, hit run again, and all was good. Total time elapsed: 1 min. Probably saved me hours! – John Lyon Aug 18 '14 at 05:07
  • 4
    In case you cannot disable antivirus, running the build process (py2exe) twice may help. It worked for me because first time it built library.zip and failed. Second time, it was able build the executable. – syam Nov 02 '14 at 08:35
  • @syam Thanks for mentioning this =) – thclpr Mar 03 '15 at 17:48
  • perfect answer! As my AV didnt popup any warning/error, I wouldnt have thought of this any time soon – pHiL Feb 21 '16 at 16:44
3

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(...)
  • This worked for me when nothing else did. It is also good because it permanently patches the problem and removes the Pause and Unpause Steps from my process flow. – Boergler May 15 '19 at 16:18
1

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).

seeiespi
  • 3,628
  • 2
  • 35
  • 37
0

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

Jona
  • 1,023
  • 2
  • 15
  • 39
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - [From Review](/review/low-quality-posts/11012129) – Fabio Lamanna Jan 24 '16 at 21:25
  • @FabioLamanna I ran into a similar problem as the author, and this is a solution that worked for me. for others that might end up in my shoes, this is a good resource to have if they come across this post. – Jona Jan 24 '16 at 21:36
0

May be an issue if you use a folder under C:\Users. Windows apparently does not like it. Just run pyinstaller from another folder (after moving your files to that other folder). I moved my python scripts under C:\Temp and it worked like a charm where under C:\Users, I had the same permission issue (even when the cmd running as admin user).

Fabian
  • 133
  • 1
  • 8