1

I'm having trouble running a compiled app which includes singleton, the .pyw compilation proccess goes just fine, but when I attempt to run the resulting .exe, it writes an error log with the message shown below:

Traceback (most recent call last):
  File "main.pyw", line 16, in <module>
  File "tendo\singleton.pyc", line 20, in __init__
AttributeError: 'module' object has no attribute '__file__'

this is how I'm calling singleton:

from tendo import singleton
me = singleton.SingleInstance()
CoCoMonk
  • 512
  • 1
  • 5
  • 9
  • 1
    Please put your code too in order to be more specific – GodMan Sep 18 '12 at 16:39
  • How are you "compiling" this app? `py2exe`? Something else? Does it work before being packed into an `.exe` file? – senderle Sep 18 '12 at 17:32
  • @Senderle: I'm using py2exe to make the windows executable; – CoCoMonk Sep 18 '12 at 18:29
  • @GodMan: The code is too long, and anyway, if I don't include tendo, I can make use of the app. but the use of singleton is a requirement, since I can't allow more than 1 instance of the application. – CoCoMonk Sep 18 '12 at 18:36

1 Answers1

1

The tendo's singleton module makes use of sys.modules['__main__'].__file__ to find the main directory. In py2exe it doesn't exist, that's why you get this error.

You can fix it with this answer. In tendo/singleton.py, line 20 you have:

self.lockfile = os.path.normpath(tempfile.gettempdir() + '/' +
  os.path.splitext(os.path.abspath(sys.modules['__main__'].__file__))[0] \
  .replace("/","-").replace(":","").replace("\\","-") + '-%s' % flavor_id +'.lock')

Replace with something like this:

path_to_script = get_main_dir()  #see linkd answer
self.lockfile = os.path.normpath(tempfile.gettempdir() + '/' +  path_to_script
  .replace("/","-").replace(":","").replace("\\","-") + '-%s' % flavor_id +'.lock')

Report this as an issue to the author, and/or make a pull request with the fix.

Community
  • 1
  • 1
CharlesB
  • 86,532
  • 28
  • 194
  • 218