致命的 Python 错误:initfsencoding:无法加载文件系统编解码器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/54087049/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 20:25:36  来源:igfitidea点击:

Fatal Python error: initfsencoding: unable to load the file system codec

pythonexepyinstallercodec

提问by EcSync

I have created a .exe file of a simple script with intentions to run it on a server however I cannot seem to figure out what this fault means or find any answers online. The fault code is as follows:

我创建了一个简单脚本的 .exe 文件,打算在服务器上运行它,但是我似乎无法弄清楚这个错误意味着什么或在线找到任何答案。故障代码如下:

Fatal Python error: initfsencoding: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00003c8c (most recent call first):

To get this far I used pyinstaller

为了做到这一点,我使用了 pyinstaller

pyinstaller --onefile MyScript.py

When this didn't work I also tried

当这不起作用时,我也尝试过

pyinstaller MyScript.py

I am running on windows 10, python 3.7 within admin command prompt, within a C:\ file directory.

我在 Windows 10、python 3.7 的管理命令提示符下运行,在 C:\ 文件目录中。

My sys.path is

我的 sys.path 是

['', 'C:\Users\user\AppData\Local\Programs\Python\Python37-32\python37.zip', 'C:\Users\user\AppData\Local\Programs\Python\Python37-32\DLLs', 'C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib', 'C:\Users\user\AppData\Local\Programs\Python\Python37-32', 'C:\Users\user\AppData\Roaming\Python\Python37\site-packages', 'C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages', 'C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\win32', 'C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\win32\lib', 'C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\Pythonwin']

['', 'C:\Users\user\AppData\Local\Programs\Python\Python37-32\python37.zip', 'C:\Users\user\AppData\Local\Programs\Python\Python37-32\DLLs ', 'C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib', 'C:\Users\user\AppData\Local\Programs\Python\Python37-32', 'C:\用户\用户\AppData\Roaming\Python\Python37\site-packages'、'C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages'、'C:\Users\用户\AppData\Local\Programs\Python\Python37-32\lib\site-packages\win32', 'C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\win32 \lib', 'C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\Pythonwin']

Any help is appreciated

任何帮助表示赞赏

采纳答案by EcSync

So I managed to fix this issue by rebuilding the exe file and dumping all of the site packages from python home to the exe dist folder. Will go through them again to figure out which one was causing issues.

所以我设法通过重建 exe 文件并将所有站点包从 python home 转储到 exe dist 文件夹来解决这个问题。将再次检查它们以找出导致问题的原因。

EDIT

编辑

I narrowed this down and found the specific issue was the plotly package was not being dumped into the dist folder. I am not sure why but this is the only package I was using that pyinstaller wouldn't pick up

我缩小了范围,发现具体问题是 plotly 包没有被转储到 dist 文件夹中。我不知道为什么,但这是我使用的唯一一个 pyinstaller 无法接收的软件包

回答by Vineeth Sai

Looks like this is happening due to some problem in python installation. Are you sure python is configured properly? Did you add it into ENVIRONMENT VARIABLES?

看起来这是由于python安装中的一些问题而发生的。你确定python配置正确吗?你加进去了ENVIRONMENT VARIABLES吗?

Most likely it is because your PYTHONPATH,i.e the one that locates the site-packagesis improperly configured. It should work fine once you point PYTHONPATHto the corrent python3.xinstallation.

很可能是因为您的PYTHONPATH,即定位 的那个site-packages配置不正确。一旦您指向PYTHONPATH相应的python3.x安装,它应该可以正常工作。

Once launch pythonfrom your cmd and check which site-packages it is loading.

python从您的 cmd启动并检查它正在加载哪些站点包。

import sys
sys.path

And then verify what is actually present in your PYTHONHOME

然后验证您的产品中实际存在的内容 PYTHONHOME