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

Win10升Win11+Python3.9.7升3.11.13后PyInstaller打包失败求助

解决方案

一、解决PyInstaller打包报错 TypeError: expected string or bytes-like object, got 'NoneType'

  • 升级PyInstaller至兼容Python 3.11的版本:
    Python 3.11需要PyInstaller 5.7.0及以上版本支持,执行命令:
    pip install --upgrade pyinstaller
    # 若使用conda环境,可执行:
    conda install -c conda-forge pyinstaller --force-reinstall
    
  • 清理PyInstaller缓存文件:
    删除打包生成的build、dist文件夹,以及自动生成的.spec文件(如果存在),然后重新执行打包命令。
  • 检查打包路径与命令:
    确保脚本路径无特殊字符,尝试使用绝对路径执行打包,例如:
    pyinstaller "D:\your_script_path\your_script.py"
    
  • 排查动态导入问题:
    若脚本中存在动态导入模块的代码,PyInstaller可能无法自动识别,需通过--hidden-import参数手动指定缺失的模块,例如:
    pyinstaller --hidden-import=your_module your_script.py
    

二、解决numpy报错 AttributeError: module 'numpy' has no attribute 'bool'

  • 修改代码适配新版本numpy:
    numpy 1.26+移除了numpy.bool别名,将代码中所有np.bool替换为np.bool_或Python内置的bool。
  • 安装兼容版本的numpy:
    若不想修改代码,可安装仍保留numpy.bool别名的版本,例如:
    conda install numpy==1.25.2
    
  • 创建隔离的conda环境:
    避免环境依赖冲突,新建一个指定版本的环境:
    conda create -n py311_env python=3.11 numpy=1.25.2 pyinstaller
    conda activate py311_env
    
    在该环境中运行脚本并执行打包操作。

内容的提问来源于stack exchange,提问作者Anh Quân Cổ Tấn

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 11:26:01