Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ModuleNotFoundError: No module named 'encodings'

716 views
Skip to first unread message

Jason Qian

unread,
Sep 6, 2018, 3:47:04 PM9/6/18
to
Hi

Need some help.

I have a C++ application that invokes Python.

...
Py_SetPythonHome("python_path");
Py_Initialize();

This works fine on Python 3.6.4 version, but got errors on Python 3.7.0
when calling Py_Initialize(),

Fatal Python error: initfsencoding: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'


Thanks for the help
Jason

Thomas Jollans

unread,
Sep 6, 2018, 5:29:35 PM9/6/18
to
On 09/06/2018 09:46 PM, Jason Qian via Python-list wrote:
> Hi
>
> Need some help.
>
> I have a C++ application that invokes Python.
>
> ...
> Py_SetPythonHome("python_path");

This isn't actually a line in your code, is it? For one thing,
Py_SetPythonHome expects a wchar_t*...

> Py_Initialize();
>
> This works fine on Python 3.6.4 version, but got errors on Python 3.7.0
> when calling Py_Initialize(),
>
> Fatal Python error: initfsencoding: unable to load the file system codec
> ModuleNotFoundError: No module named 'encodings'

So, Python can't find a core module. This either means your Python 3.7
build is broken, or it doesn't know where to look. Perhaps whatever it
is you're actually passing to Py_SetPythonHome needs to be changed to
point to the right place? (i.e. maybe you're giving it the location of
the Python 3.6 library rather than the Python 3.7 one)

-- Thomas

Jason Qian

unread,
Sep 7, 2018, 11:14:04 AM9/7/18
to
Thanks Thomas,

You are right, this seems the Python home configuration issue.

One more question.

Is there a way I can catch the error ( Fatal Python error: initfsencoding:
..) as exception in the c code ?

try{
Py_Initialize();
}catch(xxx)
{

}


Thanks
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Thomas Jollans

unread,
Sep 7, 2018, 12:49:17 PM9/7/18
to
On 2018-09-07 17:13, Jason Qian via Python-list wrote:
> Thanks Thomas,
>
> You are right, this seems the Python home configuration issue.
>
> One more question.
>
> Is there a way I can catch the error ( Fatal Python error: initfsencoding:
> ..) as exception in the c code ?

It's a fatal error, which means it aborts.

As I'm sure you know, C doesn't have exceptions. You might be able to
handle SIGABRT, I'm not sure.
0 new messages