[Fixed]-"fatal python error: init_fs_encoding: failed to get the python codec of the filesystem encoding"


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

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

If you set these two environment variables to nil, the problem should disappear:

set PYTHONHOME=
set PYTHONPATH=

To resolve the "Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding, when trying to start uwsgi" error, you can try the following steps:

  1. Check if your Python installation is configured correctly and has the necessary codecs installed.
  2. Verify that the environment variables related to Python are correctly set.
  3. Ensure that you are using a compatible version of uWSGI with your Python installation.
  4. Try updating your Python installation to the latest version. Sometimes, issues related to filesystem encoding are fixed in newer releases.
  5. Check if there are any conflicting installations of Python or uWSGI that might be causing the issue.
  6. Inspect the uWSGI configuration files and command-line parameters to see if there are any misconfigurations that could lead to this error.
  7. If you're running uWSGI in a virtual environment, make sure that the virtual environment is activated and that it contains all the necessary dependencies.

"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 on Linux, please post a comment here!"

"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
"Fatal Python error on Windows 10 when I try to access Python from command prompt"

"Press the Windows logo on the Toolbar.

Type and open 'Edit the system environment variables'.

In the Advanced tab, press the 'Environment Variables' button.

For System variables, press the 'New' button.

Variable name will be PYTHONHOME and Variable value will be the path where the python.exe is located (i.e. c:/users/administrator/anaconda3/envs/my_env_name). Then press OK.

Again, for System variables, press the 'New' button.

Variable name will be PYTHONPATH and Variable value will be the path of the site-packages folder (i.e. C:/Users/Administrator/anaconda3/envs/my_env_name/Lib/site-packages). Then press OK."