rdmenezes / cefpython

Automatically exported from code.google.com/p/cefpython
1 stars 0 forks source link

GetModuleDirectory may return incorrect path when packaged with py2exe as a single executable that extracts to a temp directory #84

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
If the executable is in a different directory than the
PYD file, then the returned directory will be incorrect
(this is a case when using py2exe single executable feature
that extracts python files to a temp directory).

Here is the source of the GetModuleDirectory() function:

    if hasattr(sys, "frozen"):
        path = os.path.dirname(sys.executable)
    elif "__file__" in globals():
        path = os.path.dirname(os.path.realpath(__file__))
    else:
        path = os.getcwd()

It should be changed to use only the __file__ variable.

Test it with py2exe and pyinstaller.

Original issue reported on code.google.com by czarek.t...@gmail.com on 4 Sep 2013 at 10:01

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I got a problem about this topic. Function cefpython.GetModuleDirectory() 
should handle Unicode chars.
When my program run with py2exe, got error:
[1206/215620:ERROR:child_process_launcher.cc(326)] Failed to launch child 
process

so I tried to log setting.browser_subprocess_path.
When the program run with python enviroment, it's OK:
12/08 11:48:31 - settings:{'log_file': 'D:\\GUI\\kangdong\\html\\debug.log', 
'log_severity': 2, 'release_dcheck_enabled': True, 'browser_subprocess_path': 
'D:\\Python27\\lib\\site-packages\\cefpython3/subprocess'}

With py2exe, while the path including some unicode chars, got the 
child_process_launcher error above. 
12/08 12:06:21 - settings:{'log_file': 
'D:\\GUI\\kangdong\\html\\\xd6\xd0\xce\xc4path\\debug.log', 'log_severity': 2, 
'release_dcheck_enabled': True, 'browser_subprocess_path': 
'D:\\GUI\\kangdong\\html\\\xd6\xd0\xce\xc4path/subprocess'}

Original comment by elise...@gmail.com on 8 Dec 2014 at 4:09

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
@#2 eliseoop: See https://code.google.com/p/cefpython/issues/detail?id=151#c4

Original comment by czarek.t...@gmail.com on 8 Dec 2014 at 12:29

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
To avoid extraction to a temp directory and the issue with GetModuleDirectory, 
set py2exe options "bundle_files" to 1, "compressed" to True and "zipfile" to 
None. For more details see: http://stackoverflow.com/a/113014/623622

Original comment by czarek.t...@gmail.com on 8 Dec 2014 at 12:36

GoogleCodeExporter commented 9 years ago
To avoid extraction to a temp directory set py2exe options "bundle_files" to 1, 
"compressed" to True and "zipfile" to None. For more details see: 
http://stackoverflow.com/a/113014/623622 . Not sure if this is going to work 
with CEF though.

This isn't a common usage to have a single executable extracting to a temp 
directory. Application should provide a standalone installer. In such case 
GetModuleDirectory will work just fine. Marking as won't fix as this is 
non-standard use and should rather be fixed in application code.

Original comment by czarek.t...@gmail.com on 8 Dec 2014 at 12:46