【发布时间】:2017-03-30 18:26:34
【问题描述】:
这是一个 CPython 程序,它尝试使用空的 sys.path 初始化解释器:
#include <Python.h>
int main(int argc, char** argv)
{
wchar_t* program = NULL;
wchar_t* sys_path = NULL;
Py_NoSiteFlag = 1;
program = Py_DecodeLocale(argv[0], NULL);
Py_SetProgramName(program);
sys_path = Py_DecodeLocale("", NULL);
Py_SetPath(sys_path);
Py_Initialize();
PyMem_RawFree(program);
PyMem_RawFree(sys_path);
Py_Finalize();
}
执行上面的程序会引发以下错误:
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
Current thread 0x00007ffff7fc6700 (most recent call first):
Signal: SIGABRT (Aborted)
那么 Python 3.5 标准库中的哪些包和模块,除了 encodings 包之外,是绝对需要运行 Python 3.5 解释器的?在我看来,文档中没有此信息。
【问题讨论】:
-
您可以通过运行解释器进行测试,然后查看导入模块的字典以查看其中包含的内容。
标签: python python-3.x python-3.5 python-internals python-embedding