Can't load Tkinter in embedded Python interpreter on Windows

Kevin Walzer kw at codebykevin.com
Tue Apr 5 07:26:17 EDT 2016


I am trying to build a stub exe on Windows that embeds Python and 
launches my Tkinter app. I want a full-blown exe program starter because 
the various Python freezing tools (py2exe, pyinstaller) do not work to 
my satisfaction with Python 3.5.
I am able to get the executable built but I cannot get it to load 
Tkinter and run. The current error is:
"AttributeError: module 'sys' has no attribute 'argv'"
when called from the Tkinter init method.
Here is my command-line invocation for the compiler:
---
gcc quickwho.c -I 
\C:\Users\kevin\AppData\Local\Programs\Python\Python35\include 
-LC:\Users\kevin\AppData\Local\Programs\Python\Python35\libs 
-LC:\Users\kevin\AppData\Local\Programs\Python\Python35\DLLs -lShlwapi 
-lpython35 -o quickwho.exe
----
And here is my C stub launcher:
#include 
<C:/Users/kevin/AppData/Local/Programs/Python/Python35/include/Python.h>
#include <Windows.h>
#include <shlobj.h>
#include <shlwapi.h>
#include <tchar.h>
int main(int argc, char *argv[])
{
 Py_SetProgramName(argv[0]);
 Py_Initialize();
 TCHAR exedir [MAX_PATH];
 #if 0
 GetModuleFileName(NULL, exedir, MAX_PATH);
 _tprintf("%s/n", exedir);
 PathRemoveFileSpec(exedir);
 _tprintf("%s/n", exedir);
 #endif
 /*Get the module's full path, and set to the current working 
directory.*/
 if (!GetModuleFileName(NULL, exedir, MAX_PATH)) {
 TCHAR errmsg[512];
 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0, 
GetLastError(),0,errmsg,1024,NULL);
 _tprintf( TEXT("The path is %s, and the error is %s/n"), exedir, 
errmsg );
 }
 if (!PathRemoveFileSpec(exedir)) {
 TCHAR errmsg[512];
 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0, 
GetLastError(),0,errmsg,1024,NULL);
 _tprintf( TEXT("The target dir is %s, and the error is %s/n"), 
exedir, errmsg );
 }
 if (!SetCurrentDirectory(exedir)) {
 TCHAR errmsg[512];
 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0, 
GetLastError(),0,errmsg,1024,NULL);
 _tprintf( TEXT("The working dir is %s, and the error is %s/n"), 
exedir,errmsg );
 }
 PyRun_SimpleString("exec(open(\"QuickWho.py\").read())");
 Py_Finalize();
 return 0;
}
Can anyone suggest what I might do to get Tkinter to load and run my exe?
Thanks,
Kevin
-- 
Kevin Walzer
Code by Kevin/Mobile Code by Kevin
http://www.codebykevin.com
http://www.wtmobilesoftware.com


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /