【发布时间】:2016-08-22 11:44:48
【问题描述】:
我的路径上首先有 anaconda Python,但一个简单的 Python 嵌入示例显示了我的 Mac 系统 python 版本,即使 ProgramFullPath 正确指向 anaconda python。有没有办法正确查找/使用 anaconda python?
小例子:
#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;
}
我编译,
gcc `python-config --cflags` example.c `python-config --ldflags`
或者,扩展python-config 调用的结果,
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
运行程序给出,
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版本。
【问题讨论】:
标签: python python-2.7 anaconda embedding python-embedding