試了很多方式,包括升級(jí)或降級(jí)pydantic模塊的版本讹躯,但是打包時(shí)依然提示
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
后來仔細(xì)分析了一下報(bào)錯(cuò)的信息然评,感覺這個(gè)和PyInstaller有關(guān)尘惧,因此嘗試一下升級(jí)PyInstaller再打包炬转,發(fā)現(xiàn)依然不行
看來pyinstaller的最新版本并沒有修復(fù)這個(gè)問題,因此我們點(diǎn)進(jìn)報(bào)錯(cuò)處的代碼述吸,發(fā)現(xiàn)這里應(yīng)該是要讀pydantic的版本忿族,但是2.1.0之后版本的pydantic是通過version讀版本的,因此必然沒有compiled屬性蝌矛,所以修改一下這里的代碼再打包道批,就不會(huì)再報(bào)錯(cuò)了