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

使用PyInstaller将含Tkinter与Selenium的Python代码打包为EXE时出现pre-safe-import-module hook失败错误

Fixing PyInstaller "pre-safe-import-module hook failed" Error When Packing Tkinter + Selenium Code

Looks like you're hitting a common compatibility snag between PyInstaller's hook for setuptools.extern.six.moves and newer versions of setuptools/six. Let's walk through practical fixes step by step:

1. Upgrade Core Dependencies First

This is the most likely fix—outdated versions of PyInstaller, setuptools, or six often trigger this hook failure. Run these commands to grab the latest stable releases:

pip install --upgrade pyinstaller setuptools six

After upgrading, re-run your original PyInstaller command and check if the error clears up.

2. Exclude the Problematic Six Module Hook

If upgrading doesn't resolve the issue, explicitly tell PyInstaller to skip processing the broken hook. Modify your pack command like this:

pyinstaller --noconfirm --onedir --console --exclude-module setuptools.extern.six.moves --icon "D:/fiver/amazone/Danleech-Simple-Amazon.ico" "D:/fiver/amazone/guit/onlyui.py"

This bypasses the problematic submodule analysis that's causing the crash.

3. Use a Clean Virtual Environment (Avoid Anaconda for Packing)

Anaconda environments often include pre-modified packages that clash with PyInstaller. Try setting up a fresh venv to eliminate dependency conflicts:

  • Create and activate the environment:
    python -m venv amazon-pack-env
    # Windows Command Prompt:
    amazon-pack-env\Scripts\activate.bat
    # Windows PowerShell:
    amazon-pack-env\Scripts\Activate.ps1
    
  • Install your dependencies in this clean space:
    pip install selenium webdriver-manager numpy argparse
    
  • Run your PyInstaller command from the activated environment.

4. Simplify Your Command for Debugging

Strip down your command to the basics first to isolate the issue:

pyinstaller --console "D:/fiver/amazone/guit/onlyui.py"

If this works, gradually add back flags like --onedir, --icon, and --noconfirm one by one to pinpoint any additional conflicts.

Bonus: Handling WebDriver Manager

Since you're using webdriver_manager, ensure PyInstaller includes all its files by adding --collect-all webdriver_manager to your command. This prevents post-pack errors where the driver can't be located.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.29 11:57:49