The Python Oracle

Access denied using Py2exe

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Melt

--

Chapters
00:00 Access Denied Using Py2exe
00:55 Accepted Answer Score 41
01:18 Answer 2 Score 1
01:31 Answer 3 Score 0
01:44 Answer 4 Score 3
02:14 Thank you

--

Full question
https://stackoverflow.com/questions/2184...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #windowsservices #py2exe

#avk47



ACCEPTED ANSWER

Score 41


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!




ANSWER 2

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



ANSWER 3

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




ANSWER 4

Score 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