Py_SetProgramName() and prefixes

Marko Havu marko.havu at jyu.fi
Thu Aug 28 08:00:40 EDT 2014


I wrote earlier:

> While doing some testing, I stumbled across some weird behavior on Python 3.3 and 3.4: Py_GetPrefix(), Py_GetPath() and other functions that return paths that are supposed to be set by Py_SetProgramName() all return just ”/”:
> 
> ---------------- main.c ----------------
> #include <Python.h>
> #include <stdio.h>
> #include <stdlib.h>
> 
> int main(int argc, const char * argv[])
> {
>  printf("path: %s\n", getenv("PATH"));
>  Py_SetProgramName(L"/anaconda/envs/python3.4/bin/python");
>  Py_Initialize();
>  wprintf(L"prefix: %s\n", Py_GetPrefix());
>  PyRun_InteractiveLoop(stdin, "<stdin>");
>  Py_Finalize();
> 
>  return EXIT_SUCCESS;
> }
> ----------------

Doh. It’s supposed to be %S, not %s. When I fix that, the prefix is as expected, but I still have the original problem of Py_Initialize() not being able to find python in the path.

- Marko




More information about the Python-list mailing list