[Solved] Fatal Python error: initfsencoding: unable to load the file system codec

I have created a .exe file of a simple script with intentions to run it on a server however I cannot seem to figure out what this fault means or find any answers online. The fault code is as follows:

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

Current thread 0x00003c8c (most recent call first):

To get this far I used pyinstaller

pyinstaller --onefile MyScript.py

When this didn’t work I also tried

pyinstaller MyScript.py

I am running on windows 10, python 3.7 within admin command prompt, within a C: file directory.

My sys.path is

[”, ‘C:UsersuserAppDataLocalProgramsPythonPython37-32python37.zip’, ‘C:UsersuserAppDataLocalProgramsPythonPython37-32DLLs’, ‘C:UsersuserAppDataLocalProgramsPythonPython37-32lib’, ‘C:UsersuserAppDataLocalProgramsPythonPython37-32’, ‘C:UsersuserAppDataRoamingPythonPython37site-packages’, ‘C:UsersuserAppDataLocalProgramsPythonPython37-32libsite-packages’, ‘C:UsersuserAppDataLocalProgramsPythonPython37-32libsite-packageswin32’, ‘C:UsersuserAppDataLocalProgramsPythonPython37-32libsite-packageswin32lib’, ‘C:UsersuserAppDataLocalProgramsPythonPython37-32libsite-packagesPythonwin’]

Any help is appreciated

Enquirer: EcSync

||
Solution #1:

Looks like this is happening due to some problem in python installation. Are you sure python is configured properly?

Did you add it into ENVIRONMENT VARIABLES?

Most likely it is because your PYTHONPATH ,i.e the one that locates the site-packages is improperly configured. It should work fine once you point PYTHONPATH to the corrent python3.x installation.

Once launch python from your cmd and check which site-packages it is loading.

import sys
sys.path

And then verify what is actually present in your PYTHONHOME

Respondent: EcSync
Solution #2:

So I managed to fix this issue by rebuilding the exe file and dumping all of the site packages from python home to the exe dist folder. Will go through them again to figure out which one was causing issues.

EDIT

I narrowed this down and found the specific issue was the plotly package was not being dumped into the dist folder. I am not sure why but this is the only package I was using that pyinstaller wouldn’t pick up

Respondent: Vineeth Sai
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.