Windows 10 ModuleNotFoundError 上的致命 Python 错误:没有名为“编码”的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42512817/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fatal Python error on Windows 10 ModuleNotFoundError: No module named 'encodings'
提问by Milos Milunovic
I'm installing python on my windows 10 laptop, and when I try to run it I get this.
我正在 Windows 10 笔记本电脑上安装 python,当我尝试运行它时,我得到了这个。
Fatal Python error: Py_Initialize: unable to load the file system codec ModuleNotFoundError: No module named 'encodings' Current thread 0x0000037c (most recent call first):
致命的 Python 错误:Py_Initialize:无法加载文件系统编解码器 ModuleNotFoundError:没有名为“编码”的模块当前线程 0x0000037c(最近调用):
回答by Joe
I ran into this same issue on Windows 10. Here's how I fixed it:
我在 Windows 10 上遇到了同样的问题。这是我修复它的方法:
- 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
- 打开您的“环境变量”(在“系统属性”下)。
- 在打开的窗口中,选择“路径”行,然后单击“编辑...”按钮。
- 应该有两个环境变量
C:\Python37-32\Scripts\
,C:\Python37-32\
然后单击“确定”(确保检查这些路径值是否与 Python 安装的位置和版本相对应。) - 接下来,在“环境变量”窗口的顶部,查找
PYTHONHOME
变量并确保它也设置为C:\Python37-32
回答by Paandittya
回答by david larcher
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.
我遇到了同样的问题(我使用的是 mac,但我认为这对这个问题没有任何影响)并且它来自所选的 python 解释器路径和 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 :
我在python中使用虚拟环境来避免各种项目之间安装模块的版本冲突(我相信这是一个很好的做法)。这使我通过访问以下内容在 spyder 中配置解释器路径:
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 :
当我从不同的路径启动 spyder 时,问题就出现了。我得到与 Milo 完全相同的错误。为了解决它,我看到 2 个选项:
- change the interpreter path to match the spyder working directory
- change the spyder working directory to match the python interpreter path
- 更改解释器路径以匹配 spyder 工作目录
- 更改 spyder 工作目录以匹配 python 解释器路径
回答by caot
Before installing the python, check environment and remove the existing PYTHONHOME
, and python path
under "PATH" of environment. Or change it to the new path to be installed.
在安装 python 之前,检查环境并删除现有的PYTHONHOME
, 和python path
环境的“PATH”下。或者将其更改为要安装的新路径。
回答by Gorgorlu
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.
首先,不要忘记在单击“立即安装”之前选择“将 Python 3.x 添加到 PATH”并在安装后重新启动,以便 Windows 考虑新路径。其次,我在 Windows 7 和 64 位上使用 Phython 3 遇到了同样的问题,我通过从 Windows 7 系统环境变量中删除 PYTHONPATH 和 PYTHONHOME 来解决它,因为我之前安装了 python 2 并且这些路径指向我的 python 2 目录。我不得不简单地删除 PYTHONPATH 和 PYTHONHOME 变量。
回答by pujitha
even I had the same issue when I installed python 3.7 beta version, I resolved it by following these steps :
即使我在安装 python 3.7 beta 版本时也遇到了同样的问题,我按照以下步骤解决了它:
- 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
- 如果您没有安装以前版本的python并且已经为该版本设置了环境变量和路径,只需删除路径和环境变量
2.run the downloaded python 3.7 exe file as administrator
2.以管理员身份运行下载的python 3.7 exe文件
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.
3.在安装结束时,如果它询问路径长度的权限,只需单击它。现在在命令行中输入“python”并查看,它应该可以工作。
回答by DrKNa
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
关闭所有 CMD 或控制台模拟器。
转到系统环境设置并清除所有旧的 Python 路径或环境设置。确保您还检查了用户和系统设置中的 PATH。
再试一次
python -V
,看看你能不能运行它。- 如果您已经删除了所有 Python 环境设置,我建议您重新安装 Python 并
Add Python to PATH
在安装过程中打开该设置。
- 如果您已经删除了所有 Python 环境设置,我建议您重新安装 Python 并