Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8b2b3ce

Browse files
committed
Two changes:
(1) Use Py_GetPythonHome() instead of getenv("PYTHONHOME"); (2) Mark Hammond's patch to search for .pyc/.pyo landmark as well.
1 parent 76310fc commit 8b2b3ce

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

PC/getpathp.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ calculate_path()
307307
char argv0_path[MAXPATHLEN+1];
308308
char *buf;
309309
int bufsz;
310-
char *pythonhome = getenv("PYTHONHOME");
310+
char *pythonhome = Py_GetPythonHome();
311311
char *envpath = getenv("PYTHONPATH");
312312
#ifdef MS_WIN32
313313
char *machinepath, *userpath;
@@ -329,8 +329,19 @@ calculate_path()
329329
if (pythonhome == NULL || *pythonhome == '\0') {
330330
if (search_for_prefix(argv0_path, LANDMARK))
331331
pythonhome = prefix;
332-
else
333-
pythonhome = NULL;
332+
else {
333+
/* Couldnt find a source version - lets see if a compiled version exists. */
334+
char LANDMARK_Look[MAX_PATH+1];
335+
strcpy(LANDMARK_Look, LANDMARK);
336+
/* Turn it into ".pyc" or ".pyc" depending on the current mode. */
337+
strcat(LANDMARK_Look, Py_OptimizeFlag ? "o": "c");
338+
/* And search again */
339+
if (search_for_prefix(argv0_path, LANDMARK_Look))
340+
pythonhome = prefix;
341+
else
342+
/* Give up in disgust - just use the default! */
343+
pythonhome = NULL;
344+
}
334345
}
335346
else
336347
strcpy(prefix, pythonhome);
@@ -478,3 +489,4 @@ Py_GetProgramFullPath()
478489
calculate_path();
479490
return progpath;
480491
}
492+

0 commit comments

Comments
 (0)