Reputation: 462
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):
Upvotes: 37
Views: 144257
Reputation: 239
If this issue is happening to you in a virtual environment, just delete it and create another. It worked for me.
Upvotes: 0
Reputation: 6154
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.
Upvotes: 1
Reputation: 3318
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.
Upvotes: 1
Reputation: 69
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:
Upvotes: 1
Reputation: 55
I am not sure why this question is still here without a solution. I just encountered this and solved by this:
Close all CMD or console emulators.
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.
Try again python -V
and see if you can run it or not.
Add Python to PATH
setting during installation.Upvotes: 0
Reputation: 11
Even I had the same issue when I installed the Python 3.7 beta version, and I resolved it by following these steps:
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
Run the downloaded Python 3.7 EXE file file as administrator
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.
Upvotes: 0
Reputation: 21
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.
Upvotes: 1
Reputation: 935
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.
Upvotes: 3
Reputation: 3032
I ran into this same issue on Windows 10. Here's how I fixed it:
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.)PYTHONHOME
variable and make sure that it is also set to C:\Python37-32
Upvotes: 35