Solving Fatal Python Error: Unable to Load the File System Codec

Solving Fatal Python Error: Unable to Load the File System Codec is an error which occurs when you have faulty environment variables for python or even a faulty python installation.

This post is my attempt to explain to you why this error occurs and how you can solve it, I will also include multiple solutions that could be considered as alternative fixes to the error.

Exploring Fatal Python Error: Unable to Load the File System Codec

This error occurs when you have faulty environment variables for python or even a faulty python installation.

The error should look like this. Double check in order to avoid mixing between errors.

                                                                       #
Fatal Python error: Py_Initialize: unable to load the file system codec ModuleNotFoundError: 
No module named 'encodings' Current thread 0x0000037c (most recent call first):
                                                                       #

Bellow are the solutions which worked for me and will help you to successfully solve your problem.

Solution 1 : Correctly add python to your Environment Variables

The first solution is to Correctly add python to your Environment Variables, this error usually happens when you do not add python to your Environment Variable the ‘right way’ or when you are not working with virtual environments.

I strongly recommend using Environment Variables.

First, go to the bottom left on windows and in the search bar type Environment Variables.

Click on the program, and then click Environment Variables at the bottom.

Look for path and then click edit. A list should appear and usually at the top of the list you should see two paths.

This is from my machine by the way I has a dell laptop with python 3.10 and windows

                                                                       #
C:\Users\dell\AppData\Local\Programs\Python\Python310\
                                                                       #
                                                                       #
C:\Users\dell\AppData\Local\Programs\Python\Python310\Scripts\
                                                                       #

Edit the two paths so that they match the location of your python installation.

Sometimes, for example the variable path points to python 3.9 while you have python 3.0, you should edit it so you have a match.

Finally, look for this variable PYTHONHOME and edit it to point to where python is installed, for me it is.

                                                                       #
C:\Users\dell\AppData\Local\Programs\Python\Python310\
                                                                       #

Now, the error should be gone.

If this solution does not fix your problem you can try the second and last solution.

Solution 2 : run the python installer as an administrator and/or delete the variables PYTHONPATH and PYTHONHOME

This solution is similar to the solution above, but does not require a lot of work.

The trick is to start by uninstalling python from your machine completely.

Then you should run the python installer as an administrator.

Pay attention to this, “Add Python 3.x to PATH” will appear and you should check it during the installation.

If you do not do that then the new path will not be taken into account by Windows.

If you do not want to work with environment variables just navigate there like we did above and delete

the variable PYTHONHOME and the variable PYTHONPATH.

The solution should be enough, please try the final solution if this fails.

If this article has been useful for your particular case, consider donating to our Kofi account, there is a red button at the top of this page.

Summing-up

The article is over, I hope I have been able to help you solve this error or at least guide you in the right direction, check out other solutions to different errors you can do that by using the search bar on top of this page.

Keep learning, keep coding guys, cheers. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/