美文网首页@IT·互联网
pyinstaller 打包包含pydantic模块的代码时报错

pyinstaller 打包包含pydantic模块的代码时报错

作者: _icey_ | 来源:发表于2023-12-21 13:44 被阅读0次

试了很多方式,包括升级或降级pydantic模块的版本,但是打包时依然提示
File "C:\Users\xxxxx\AppData\Roaming\Python\Python39\site-packages\PyInstaller\utils\hooks_init_.py",
line 285, in get_module_attribute
raise AttributeError(f"Failed to retrieve attribute {attr_name} from module {module_name}") from e
AttributeError: Failed to retrieve attribute compiled from module pydantic

后来仔细分析了一下报错的信息,感觉这个和PyInstaller有关,因此尝试一下升级PyInstaller再打包,发现依然不行

升级前pyinstaller的版本.png 升级后pyinstaller的版本.png

看来pyinstaller的最新版本并没有修复这个问题,因此我们点进报错处的代码,发现这里应该是要读pydantic的版本,但是2.1.0之后版本的pydantic是通过version读版本的,因此必然没有compiled属性,所以修改一下这里的代码再打包,就不会再报错了

修改后的代码.png

相关文章

网友评论

    本文标题:pyinstaller 打包包含pydantic模块的代码时报错

    本文链接:https://www.haomeiwen.com/subject/tktfndtx.html