私は自分のパス上で最初にanaconda Pythonを持っていますが、代わりにProgramFullPath
が正しくanaconda pythonを指していても、単純なPythonの埋め込み例が私のMacシステムのpythonバージョンを示しています。 anaconda pythonを正しく検索/使用する方法はありますか?私はPythonを埋め込む:ProgramFullPathと矛盾するバージョン
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
は、プログラムを実行すると、
gcc `python-config --cflags` example.c `python-config --ldflags`
または、呼び出しの結果を拡張し、で与えるコンパイル
#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;
}
:
最小限の例
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
これはEmbed python in c++: choose python versionと同じ問題のようです。私もPYTHONHOME
、Py_SetProgramName
、Py_SetPythonHome
と設定しようとしましたが、Python_GetVersion()
を取得してanacondaバージョンに戻すことはできません。