我一直在使用自定义构建作为virtualenv的替代品一段时间了,而且它很棒.它需要更长的时间来构建,但实际上它可以工作,并且它永远不会搞砸.
部分内容在一个简单的python包装器中,它将一些特定的文件夹添加到库路径中,我发现它非常有用.它的代码是微不足道的:
#include <stdio.h>
#include <n/text/StringUtils.h>
#include <Python.h>
int main(int argc, char *argv[]) {
/* Setup */
Py_SetProgramName(argv[0]);
Py_Initialize();
PySys_SetArgv(argc, argv);
/* Add local path */
PyObject *sys = PyImport_ImportModule("sys");
PyObject *path = PyObject_GetAttrString(sys, "path");
/* Custom path */
char *cwd = nrealpath(argv[0]);
char *libdir = nstrpath(cwd, "python_lib", NULL);
PyList_Append(path, PyString_FromString(libdir));
free(cwd);
free(libdir);
/* Run the 'main' module */
int rtn = Py_Main(argc, argv); // <-- Notice the command line arguments.
Py_Finalize();
return rtn;
}
Run Code Online (Sandbox Code Playgroud)
那么,转向python3是对的吗?所以...
我尽职尽责地用PyByte_FromString()替换了对PyString_FromString()的调用并尝试重新编译,但它引发了错误:
/Users/doug/env/src/main.c:8:21: error: incompatible …Run Code Online (Sandbox Code Playgroud)