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

54,051

Solution 1

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

Solution 2

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

Solution 3

I had the very same error message as EcSync. Although most people are pointing to the python setup being wrong this was not the case for me - aside from the fact that my system had not changed from one day to the next when I got the error, my environment variables matched the python sys.path

EcSync solved the problem by including a missing module but their answer is downvoted. I have to add my voice to say that this error was also caused by a missing module. The clue is in the error message:

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

I simply modified my spec file to include the encodings module and then everything worked. To do this you may need to specify to pyinstaller to use the spec file provided rather than making one from scratch, and you will have to put the path to the missing module in the datas list of Analysis. See here.

Share:
54,051
EcSync
Author by

EcSync

Updated on December 02, 2021

Comments

  • EcSync
    EcSync over 2 years

    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:\Users\user\AppData\Local\Programs\Python\Python37-32\python37.zip', 'C:\Users\user\AppData\Local\Programs\Python\Python37-32\DLLs', 'C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib', 'C:\Users\user\AppData\Local\Programs\Python\Python37-32', 'C:\Users\user\AppData\Roaming\Python\Python37\site-packages', 'C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages', 'C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\win32', 'C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\win32\lib', 'C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\Pythonwin']

    Any help is appreciated

  • EcSync
    EcSync over 5 years
    I have edited the question to show what this gave me
  • Vineeth Sai
    Vineeth Sai over 5 years
    I see the path is not the same. Your python sys.path - C:\Users\user\AppData and your system path do not match. C:\Users\esinclair\AppData. here the user didn't match
  • EcSync
    EcSync over 5 years
    thats my fault i removed my name and entered user instead for the purpose of this, i missed one - the paths do all match in my terminal!
  • Vineeth Sai
    Vineeth Sai over 5 years
    I suggest you load up a virtual environment with python 3.6 and run the script from there. Make sure you load python 3.6 in that virtualenv.
  • EcSync
    EcSync over 5 years
    why would using python 3.6 make a difference?
  • Vineeth Sai
    Vineeth Sai over 5 years
    I've read through some github issues awhile ago, there were some issues with 3.7 update. And virtualenv should fix any path issues if present
  • EcSync
    EcSync over 5 years
    I think thats been fixed now, python 3.7 didnt support pyinstaller however i think thats been fixed now
  • Sammy J
    Sammy J over 4 years
    Hi, I am facing the same issue, can you tell me how did you rebuild exe file?
  • EcSync
    EcSync over 4 years
    @SammyJ no need to rebuild, just insert missing package into dist folder
  • SajanGohil
    SajanGohil about 4 years
    Does adding it as hidden import work? Did you make any changes in spec file?
  • Admin
    Admin over 2 years
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
  • Charles Sun
    Charles Sun about 2 years
    In my case, I use import sys and sys.path then find that I should use Py_SetPath to set the module lib path to my embed python interpreter