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

psycopg3与PyInstaller打包后查询UUID类型报错:无法导入_uuid

问题:psycopg与PyInstaller结合打包后无法查询UUID类型数据

我在使用psycopg搭配PyInstaller时遇到了一个异常情况:

  • 未打包成二进制文件前,查询UUID类型值的SELECT语句运行完全正常;
  • 用PyInstaller打包成单文件后,INSERT UUID类型数据可以正常执行,但执行SELECT查询时总会报错:cannot import name _uuid

我已经尝试了以下两种解决方法,但问题依然存在:

  1. 在代码中显式导入相关模块:
    import _uuid
    from uuid import UUID, uuid1, uuid3, uuid4, uuid5
    
  2. 调整PyInstaller打包命令,添加隐藏导入和运行时钩子:
    $ pyinstaller --onefile --runtime-hook=runtime-hook.py --hidden-import=uuid __main__.py;
    

请问有没有人遇到过同样的异常情况?

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 06:12:01