You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PyInstaller打包Python为exe后跨机运行报错:no module named encodings

解决PyInstaller打包exe后在其他电脑报错“no module named encodings”的问题

Hey, I've run into this exact issue before—even though your code doesn't use any third-party libraries, the encodings module is a core part of Python's standard library that handles character encoding (like your decode("ASCII") call), and sometimes PyInstaller's auto-dependency analyzer misses it when building a single-file executable. Here are a few tried-and-true fixes:

  • Force include the encodings module with a hidden import
    Add the --hidden-import=encodings flag to your PyInstaller command to explicitly tell it to package this module:

    pyinstaller --onefile --hidden-import=encodings <filename>.py
    

    This works because PyInstaller doesn't always pick up implicit dependencies from standard library modules.

  • Match your Python environment to the target machine
    Make sure the Python version you used to build the exe matches the target system's architecture (32-bit vs 64-bit). A 64-bit exe won't run properly on a 32-bit Windows machine, and this can manifest as weird missing module errors. Stick to stable Python versions (3.8–3.11 tend to be most reliable for PyInstaller).

  • Collect all encodings-related files
    If the hidden import alone doesn't work, use the --collect-all flag to grab every file associated with the encodings module. This will make your exe a bit larger, but it eliminates any chance of missing components:

    pyinstaller --onefile --collect-all encodings <filename>.py
    
  • Check for missing VC++ Redistributable
    Sometimes this error is a red herring—Python's core modules depend on the Visual C++ Redistributable package. If your target machine doesn't have the version matching your Python installation (e.g., Python 3.8+ needs VC++ 2019), install that first and see if the error goes away.

Your code's bytes.fromhex(data).decode("ASCII") line directly relies on the encodings module, so making sure it's included in the package is key to fixing this.

内容的提问来源于stack exchange,提问作者taherafahimi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 20:07:56