Ich habe Anaconda Python zuerst auf meinem Pfad, aber ein einfaches Python-Einbettungsbeispiel zeigt stattdessen meine Mac-System-Python-Version, obwohl ProgramFullPath
korrekt auf Anaconda Python zeigt. Gibt es eine Möglichkeit, Anaconda Python korrekt zu finden/zu benutzen?Python einbetten: Version inkonsistent mit ProgramFullPath
Minimal Beispiel:
#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;
}
ich mit kompilieren,
gcc `python-config --cflags` example.c `python-config --ldflags`
oder erweitern die Ergebnisse der Anrufe,
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
Ausführen des Programms gibt,
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
Dies scheint das gleiche Problem wie Embed python in c++: choose python version zu sein. Ich habe auch versucht, PYTHONHOME
, Py_SetProgramName
, Py_SetPythonHome
, aber kann nicht Python_GetVersion()
, um die Anaconda-Version zurückzukehren.