@@ -973,29 +973,35 @@ static void fallback_to_python_v(const char *self_dir, char **argv,
973973 char py [MAX_PATH ];
974974 int found = 0 ;
975975
976- /* 1. Try the config first */
977- if (read_self_config (self_dir , py , sizeof (py )) && file_exists (py )) {
978- found = 1 ;
979- } else {
980- /* 2. Try common names in both the current directory AND the parent directory */
981- const char * names [] = {"python3.11" , "python3.10" , "python3.9" ,
982- "python3" , "python" , "python.exe" , NULL };
983-
984- /* We check the current dir (self_dir) and the parent dir (self_dir/..) */
985- const char * search_paths [] = {self_dir , NULL }; // We will handle parent manually for safety
986-
987- for (int i = 0 ; names [i ]; i ++ ) {
988- // Try current directory: .../Scripts/python.exe
989- snprintf (py , sizeof (py ), "%s/%s" , self_dir , names [i ]);
990- if (file_exists (py )) { found = 1 ; break ; }
991-
992- // Try parent directory: .../Scripts/../python.exe
993- snprintf (py , sizeof (py ), "%s/../%s" , self_dir , names [i ]);
994- if (file_exists (py )) { found = 1 ; break ; }
976+ /* 1. Try local / parent search (works for venvs) */
977+ const char * names [] = {"python3.11" , "python3.10" , "python3.9" , "python3" , "python" , "python.exe" , NULL };
978+ for (int i = 0 ; names [i ]; i ++ ) {
979+ snprintf (py , sizeof (py ), "%s/%s" , self_dir , names [i ]);
980+ if (file_exists (py )) { found = 1 ; break ; }
981+ snprintf (py , sizeof (py ), "%s/../%s" , self_dir , names [i ]);
982+ if (file_exists (py )) { found = 1 ; break ; }
983+ }
984+
985+ /* 2. CROSS-DRIVE FIX: If still not found, ask Windows where 'python' is */
986+ if (!found ) {
987+ FILE * fp = _popen ("where python" , "r" );
988+ if (fp ) {
989+ if (fgets (py , sizeof (py ), fp )) {
990+ // Remove newline characters
991+ py [strcspn (py , "\r\n" )] = 0 ;
992+ if (file_exists (py )) {
993+ found = 1 ;
994+ }
995+ }
996+ _pclose (fp );
995997 }
996998 }
997999
9981000 if (!found ) {
1001+ fprintf (stderr , "omnipkg: cannot find host Python for fallback\n" );
1002+ fprintf (stderr , " Self Dir: %s\n" , self_dir );
1003+ exit (1 );
1004+ }
9991005 /* VERBOSE DIAGNOSTICS: Tell the user EXACTLY where we looked */
10001006 fprintf (stderr , "omnipkg: cannot find host Python for fallback\n" );
10011007 fprintf (stderr , " Checked directory: %s\n" , self_dir );
0 commit comments