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

使用auto-py-to-exe打包Python3.9+Numpy+Sklearn程序报错求助

解决Python打包KMeans程序的两个问题:numpy警告与sklearn模块缺失

关于numpy.array_api实验性模块的警告

  • 这个警告只是numpy提示array_api子模块还处于实验开发阶段,完全不影响程序功能和打包结果,可以直接忽略。
  • 要是看着警告闹心,在你的Python脚本开头加几行代码过滤掉:
import warnings
warnings.filterwarnings("ignore", category=FutureWarning, module="numpy.array_api")

解决sklearn.metrics._pairwise_distances_reduction._datasets_pair缺失的问题

这是因为auto-py-to-exe依赖的PyInstaller没自动识别到sklearn的这个私有内部模块,得手动指定隐藏导入,和系统环境变量没关系,别白忙活环境变量了。

方法一:用auto-py-to-exe可视化配置添加

  1. 打开auto-py-to-exe,找到Hidden Imports(隐藏导入)输入框
  2. 输入sklearn.metrics._pairwise_distances_reduction._datasets_pair,如果后续打包还提示其他模块缺失,直接把模块名加到这里就行
  3. 重新点击打包按钮生成exe

方法二:手动编写PyInstaller spec文件(适合熟悉命令行的用户)

  1. 先在命令行运行pyinstaller --onefile 你的脚本文件名.py,生成对应的.spec文件
  2. 打开这个spec文件,找到hiddenimports参数,把缺失的模块加进去,修改后类似:
a = Analysis(
    ['你的脚本文件名.py'],
    pathex=[],
    binaries=[],
    datas=[],
    hiddenimports=['sklearn.metrics._pairwise_distances_reduction._datasets_pair'],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=None,
    noarchive=False,
)
  1. 最后用spec文件打包:pyinstaller 你的脚本文件名.spec

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 14:15:48