境:
python版本3.10.12
pyinstaller版本4.3
使用pyinstaller
对update_common.py
文件进行打包时出现异常,具体操作如下:
(venv) wsw@wsw:~/wsw/update$ pyinstaller -F update_common.py
提示:No module named _bootlocale
File "/wsw/venv/lib/python3.10/site-packages/PyInstaller/lib/modulegraph/modulegraph.py", line 1703, in _find_head_package
raise ImportError("No module named " + target_package_name)
ImportError: No module named _bootlocale
查找一些博客给出的解决方案是:
(venv) wsw@wsw:~/wsw/update$ pyinstaller -F update_common.py --exclude-module _bootlocale
可以顺利打包完成,生成可执行文件,但是在运行可执行文件的时候出现异常:
(venv) wsw@wsw:~/wsw/update$ ./update_common -v
[258332] mod is NULL - structSystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
[258332] mod is NULL - pyimod01_os_pathSystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
[258332] mod is NULL - pyimod02_archiveSystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
[258332] mod is NULL - pyimod03_importersSystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
Traceback (most recent call last):
File "PyInstaller/loader/pyiboot01_bootstrap.py", line 17, in
ModuleNotFoundError: No module named 'pyimod03_importers'
[258332] Failed to execute script pyiboot01_bootstrap
还是提示跟刚才类似的问题,一开始问题没有妥善解决,后面就僵持住了,也不好解决,博客中声音大概是pyinstaller支持版本不一致,我就看了下自己本地的环境,python版本是:3.10.12,三方库pyinstaller
的版本是4.3,
(venv) wsw@wsw:~/wsw/update$ pip list | grep pyinstall
pyinstaller 4.3
pyinstaller-hooks-contrib 2021.2
升级 pyinstaller
(venv) wsw@wsw:~/wsw/update$ pip install -U pyinstaller
可以成功升级:
(venv) wsw@wsw:~/wsw/update$ pip list | grep pyinstall
pyinstaller 6.0.0
pyinstaller-hooks-contrib 2023.9
接下来的过程打包也正常进行了,编译出的文件也能正常运行了;
issue refer:https://github.com/pyinstaller/pyinstaller/issues/5693