问题
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):
回答1:
I ran into this same issue on Windows 10. Here's how I fixed it:
- Open your 'Environment Variables' (Under 'System Properties').
- In the window that opens, select the 'Path' row, then click the 'Edit...' button.
- There should be two environment variables
C:\Python37-32\Scripts\
andC:\Python37-32\
Then click 'OK' (Make sure to check that these path values correspond to the location and version of your Python install.) - Next, in the top portion of the 'Environment Variables' window, look for the
PYTHONHOME
variable and make sure that it is also set toC:\Python37-32
回答2:
This issue has been addressed here in this thread. Apparently, running python setup as an administrator AND/OR correctly setting the environment variables solved this issue.
回答3:
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 Phython 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 python 2 directory. I had to simply to delete the PYTHONPATH and PYTHONHOME variables.
回答4:
even I had the same issue when I installed python 3.7 beta version, 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 env variable
2.run the downloaded python 3.7 exe file as administrator
3.At the end of installation if it asks the permission for path length just click on that. now type "python" in command line and see , it should work.
回答5:
Not sure why this question is still here without a solution. I just encountered this and solved by this:
Close all CMD or console emulator.
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 can you 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.
- If you have removed all Python environment settings, I recommend you to reinstall Python and turn on the
回答6:
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 ton 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 2 options :
- change the interpreter path to match the spyder working directory
- change the spyder working directory to match the python interpreter path
I hope this helps !
来源:https://stackoverflow.com/questions/42512817/fatal-python-error-on-windows-10-modulenotfounderror-no-module-named-encodings