Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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):

like image 511
Milos Milunovic Avatar asked Feb 28 '17 15:02

Milos Milunovic


People also ask

How do I fix Python fatal error?

Fix “Fatal Python Error: Unable to Load the File System Codec” in Windows 11/10. According to the possible reasons, you need to properly install the Python as well as set the Python path in system/environment variables. 1. Search for “edit the system environment variables” in Windows Search and open the matched result.


4 Answers

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-32\Scripts\ 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
like image 168
J.S. Peterson Avatar answered Oct 20 '22 04:10

J.S. Peterson


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.

like image 29
Paandittya Avatar answered Oct 20 '22 04:10

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.

like image 1
Gorgorlu Avatar answered Oct 20 '22 04:10

Gorgorlu


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
like image 1
David Avatar answered Oct 20 '22 06:10

David