Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding, when trying to start uwsgi

Solution 1:

I found a solution while browsing Bing, not Google.

I see your PYTHONHOME is set to PYTHONHOME = '/home/env3/educ'. Try to check if it is really there.

The solution for me was to remove the PYTHONHOME environment variable. For you, it can be just that, or setting that variable to another value. This worked on Windows, and would work on Linux for sure. If someone tries this, please post a comment here !

A CPython developer confirmed the solution here. :

This is not a Python bug, this is a symptom of setting PYTHONHOME and/or PYTHONPATH when they’re not needed. In nearly all cases you don’t need to set either of them;

In the case of PYTHONHOME it’s almost always a mistake to set.

Solution 2:

I solve this problem by unsetting PYTHONHOME or PYTHONPATH, because they override the virtual environment variables.

In my case this is caused by my admin's base environment. I would try removing PYTHONHOME and PYTHONPATH variables by doing

unset PYTHONPATH
unset PYTHONHOME

Solution 3:

This message is for those with the same problem who will find this page later. I couldn't start uWSGI with my config, and I had the same message in logging files.

init_fs_encoding: failed to get the Python codec of the filesystem encoding Python runtime state: core initialized ModuleNotFoundError: No module named 'encodings'

The problem was uWSGI didn't have enough permissions to access the virtual environment. When I fixed the permissions, uWSGI started my config.

Denys posted the uwsgi.ini config in his message. I guess the path to the virtual environment is wrong.

base = /home/env3/educ
projectname = educ
virtualenv = /home/env3/%(projectname)

If the virtual environment was created in the project directory, then the path should look like this:

virtualenv = /home/env3/%(projectname)/env