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

Win10虚拟机中PyInstaller打包exe提示No module requests found求助

PyInstaller打包后缺失requests模块的解决办法

以下是几种针对性的解决步骤:

  • 确认依赖安装正确
    先确保当前Python环境中已正确安装requests和pynput模块,可执行以下命令检查或重装:

    pip list | findstr "requests pynput"
    pip install --upgrade requests pynput
    
  • 使用--hidden-import参数强制导入模块
    PyInstaller的自动依赖检测可能遗漏部分模块,打包时手动指定隐藏导入:

    pyinstaller --onefile --hidden-import=requests --hidden-import=pynput.keyboard your_script_name.py
    

    替换your_script_name.py为你的实际脚本文件名。

  • 通过spec文件自定义打包配置

    1. 先生成spec配置文件:
      pyinstaller your_script_name.py
      
    2. 打开生成的.spec文件,找到hiddenimports字段,添加缺失的模块:
      a = Analysis(
          ['your_script_name.py'],
          pathex=[],
          binaries=[],
          datas=[],
          hiddenimports=['requests', 'pynput.keyboard'],  # 这里添加模块
          hookspath=[],
          hooksconfig={},
          runtime_hooks=[],
          excludes=[],
          win_no_prefer_redirects=False,
          win_private_assemblies=False,
          cipher=block_cipher,
          noarchive=False,
      )
      
    3. 基于修改后的spec文件打包:
      pyinstaller your_script_name.spec
      
  • 排查多Python环境冲突
    确保打包使用的Python环境与安装依赖的环境一致:

    • 执行where python查看当前Python路径
    • 执行pip -V确认pip对应的Python环境
      若存在多个环境,切换到正确环境后重新安装依赖并打包

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 23:25:27