Fatal Python error on Windows 10 ModuleNotFoundError: No module named 'encodings'

Question:

I’m installing Python on my Windows 10 laptop, and when I try to run it I get this:

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

Asked By: Milos Milunovic

||

Answers:

This issue has been addressed here in this thread. Apparently, running the Python setup as an administrator and/or correctly setting the environment variables solved this issue.

Answered By: Paandittya

First, don’t forget to select "Add Python 3.x to PATH" before you click on Install now and reboot after installation so that the new path is taken into account by Windows.

Second, I had the the same problem with Python 3 on Windows 7 and 64-bit and I got rid of it by deleting PYTHONPATH and PYTHONHOME from Windows 7 system environment variables, because I had a previous installation of Python 2 and those paths were pointing to my the Python 2 directory. I had to simply to delete the PYTHONPATH and PYTHONHOME variables.

Answered By: Gorgorlu

Even I had the same issue when I installed the Python 3.7 beta version, and I resolved it by following these steps:

  1. If you have nay previous version of Python installed and the environment variable and path is set for that version already, just remove the path and environment variable

  2. Run the downloaded Python 3.7 EXE file file as administrator

  3. At the end of installation if it asks the permission for path length just click on that. Now type "python" on the command line and see. It should work.

Answered By: pujitha

I am not sure why this question is still here without a solution. I just encountered this and solved by this:

  1. Close all CMD or console emulators.

  2. Go to the system environment settings and clear all old Python path or environment settings. Make sure you check the PATH in both User and System settings as well.

  3. Try again python -V and see if you can run it or not.

  • If you have removed all Python environment settings, I recommend you to reinstall Python and turn on the Add Python to PATH setting during installation.
Answered By: DrKNa

I ran into this same issue on Windows 10. Here’s how I fixed it:

  1. Open your ‘Environment Variables‘ (Under ‘System Properties‘).
  2. In the window that opens, select the ‘Path‘ row, then click the ‘Edit…‘ button.
  3. There should be two environment variables C:Python37-32Scripts and C:Python37-32 Then click ‘OK‘ (Make sure to check that these path values correspond to the location and version of your Python install.)
  4. Next, in the top portion of the ‘Environment Variables‘ window, look for the PYTHONHOME variable and make sure that it is also set to C:Python37-32
Answered By: J.S. Peterson

I had the same problem (I use a Mac, but I don’t think it makes any difference in this problem) and it was coming from the difference between the selected Python interpreter path and the current working directory in spyder.

I use virtual environments in Python to avoid version conflicts of installed modules between various projects (I believe it is a good practice). This leads me to configure the interpreter path in spyder by accessing:

preferences > python interpreter > use the following interpreter

The problem comes when I launch spyder from a different path. I get exactly the same error as Milo’s. To solve it I see two options:

  1. change the interpreter path to match the spyder working directory
  2. change the spyder working directory to match the Python interpreter path
Answered By: David

Before installing the Python interpreter, check environment and remove the existing PYTHONHOME, and python path under "PATH" of environment. Or change it to the new path to be installed.

Answered By: caot

I solved this issue by deleting my virtual environment and creating a new one. I believe in my case the error came because the old virtual environment was running on Python 3.6, which I had recently uninstalled and replaced with Python 3.8.

This is probably bad practice in general, but I don’t have any real projects where the version matters.

Answered By: rocksNwaves

If this issue is happening to you in a virtual environment, just delete it and create another. It worked for me.

Answered By: justbecause
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.