gpt4 book ai didi

Python、PyInstaller 错误 : no module named "Encodings" and system codec missing

转载 作者:太空狗 更新时间:2023-10-29 17:20:49 25 4
gpt4 key购买 nike

我正在使用 Python 3.3.3,我一直在尝试从一个简单的 .py 脚本构建一个 .exe。

我的脚本是这样的:

import encodings

print('Test')

并正确执行。

当我尝试使用 PyInstaller 使用此命令构建它时:

pyinstaller --onefile Testmodul.py

然后尝试打开我的 .exe,它显示了这个错误:Python fatal error :Py_Initialize:无法加载文件系统编解码器,ImportError:没有名为“encodings”的模块

我已经尝试在我的测试脚本中导入“编码”模块,但它仍然无法正常工作,我也尝试过 py2exe,但它也根本无法正常工作。

我做错了什么吗?我必须在我的 PATH 中设置一些东西吗? “C:\Python33”的正确路径已经包含在其中。

编辑:对于遇到这个问题的每个人:我放弃了,在全新安装 Windows 和 Python 以及所有其他东西之后,我再次尝试,与以前一样,它没有问题。它是如果你真的很绝望,值得一试!

最佳答案

这可能是因为 pyinstaller 一开始没有包含该模块。尝试以下解决方案之一。

1) 在编译期间指定模块的路径:

  • pyinstaller --onefile --paths=/path/to/module Testscript.py

2) 从 .spec 文件指定路径:

  • 首先运行此命令(在 pyinstaller 的目录中):

    python Makespec.py --onefile /path/to/yourscript.py
  • 现在您有了 .spec 文件。在文本编辑器中打开它,并将模块的路径添加到 pathex。

    pathex=['C:\\path\\to\\module']
  • 然后,构建您的程序:

     python Build.py /path/to/yourscript.spec

3) 使用隐藏的导入:

  • pyinstaller --onefile --hidden-import=modulename Testscript.py
  • 您还可以在 .spec 文件中指定 hidden-import。

关于Python、PyInstaller 错误 : no module named "Encodings" and system codec missing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42224576/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com