I have anaconda Python first on my path, but a simple Python embedding example shows my Mac system python version instead, even though ProgramFullPath
correctly points to anaconda python. Is there a way to correctly find / use anaconda python?
Minimal example:
#include <Python.h>
#include <stdio.h>
int main(void) {
Py_Initialize();
printf("Python version:\n%s\n", Py_GetVersion());
printf("Python Program Full Path:\n%s\n", Py_GetProgramFullPath());
Py_Finalize();
return 0;
}
I compile with,
gcc `python-config --cflags` example.c `python-config --ldflags`
or, expanding the results of the python-config
calls,
gcc -I/Users/ryandwyer/anaconda/include/python2.7 \
-I/Users/ryandwyer/anaconda/include/python2.7 \
-fno-strict-aliasing -I/Users/ryandwyer/anaconda/include \
-arch x86_64 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes \
example.c -lpython2.7 -ldl -framework CoreFoundation -u _PyMac_Error
Running the program gives,
Python version:
2.7.5 (default, Mar 9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)]
Python Program Full Path:
/Users/ryandwyer/anaconda/bin/python
This seems to be the same problem as Embed python in c++: choose python version. I have also tried setting PYTHONHOME
, Py_SetProgramName
, Py_SetPythonHome
, but cannot get Python_GetVersion()
to return the anaconda version.