Python 3.7环境下PyInstaller运行异常(缺失encodings模块)求助
Hey there, let's work through this PyInstaller issue you're hitting with Python 3.7.0b1 on Windows 10 64-bit. Pre-release Python versions plus older PyInstaller builds often cause these kinds of hiccups, so here's a step-by-step breakdown to fix it:
Your problem stems from two main sources:
- Python 3.7.0b1 is a pre-release version: PyInstaller 3.3.1 doesn't have full compatibility with its newer internal structures.
- Missing system dependencies & unbundled modules: The
api-ms-win-crt-*.dllwarnings point to missing Windows runtime libraries, and theencodingsmodule isn't being automatically packaged by PyInstaller.
1. Upgrade PyInstaller to a Python 3.7-compatible version
PyInstaller 3.3.1 is too old to properly support Python 3.7. You'll need a newer build that includes fixes for this version:
- First uninstall the old version:
pip uninstall pyinstaller -y - Install the latest stable release (version 3.4+ adds Python 3.7 support; 4.x+ is recommended):
pip install pyinstaller --upgrade - If stable still has issues, try the development build which often has pre-release compatibility fixes:
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
2. Force-include the encodings module
If upgrading doesn't resolve the missing encodings error, manually tell PyInstaller to bundle it:
- Add the
--hidden-importflag to your pack command:pyinstaller --hidden-import encodings your_test_script.py - Alternatively, create a
.specfile (runpyinstaller your_test_script.pyonce to generate it), then addencodingsto thehiddenimportslist:
Then re-pack using the spec file:# Example snippet from the .spec file a = Analysis(['your_test_script.py'], pathex=['C:\\path\\to\\your\\script'], binaries=[], datas=[], hiddenimports=['encodings'], # Add this line hookspath=[], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=None, noarchive=False)pyinstaller your_test_script.spec
3. Resolve missing api-ms-win-crt-*.dll warnings
These DLLs are part of the Windows Universal CRT, which Python 3.7 depends on. Fix this by:
- Installing the Visual C++ Redistributable for Visual Studio 2017 (this is the official way to get these libraries; make sure to grab the 64-bit version matching your system).
- If you can't install the redistributable, manually copy the missing DLLs from your Python installation directory (
C:\apps\python\python37) orC:\Windows\System32into the folder where your packaged executable lives.
4. Switch to a stable Python 3.7 release (optional but recommended)
Since you're using a beta version of Python 3.7, you might run into other unforeseen compatibility issues. Consider upgrading to the latest stable Python 3.7 release (like 3.7.10) — pre-release builds are great for testing, but not ideal for production or tooling compatibility.
内容的提问来源于stack exchange,提问作者joe

