Jovito Jovito - 1 year ago 71
Python Question

Which standard library modules are required to run the Python 3.5 interpreter?

Here's a CPython program that tries to initialize the interpreter with an empty


#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);

sys_path = Py_DecodeLocale("", NULL);



Executing the program above raises the following error:

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)

So which of the packages and modules in the Python 3.5 standard library, besides the
package, are absolutely required to run the Python
interpreter? This information seems to me absent from the documentation.

Answer Source

These are packages/modules that are used during interpreter start-up (as, @Charles Duffy noted in a comment, by looking in sys.modules.

The result depends on whether you have site enabled or not (your Py_NoSiteFlag = 1; implies this isn't the case but anyway, I'll give both options :-).

With site enabled, you could run Python using the following:               encodings         

and, with site disabled, you're stripped down to the following 6:  encodings

when invoked through C with Py_Initialize() I'm guessing might not be actually needed.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download