python程序打包成exe——pyinstaller

  1. 安装pyinstaller包
    pip install pyinstaller
  2. 使用pyinstaller命令
    常用参数 https://www.jb51.net/article/206825.htm
    eg:
    pyinstaller -w --distpath ..\DirectRun -y -F -n 手势操作.exe --add-data="E:\anaconda\Lib\site-packages\mediapipe\modules;mediapipe\modules" -i ..\minicar.ico hands_controller.py
    

​ -w 不显示命令行窗口(不加则默认显示命令行窗口)
–distpath 生成文件放在哪里(不加则生成到当前目录的dist文件夹下)
​ -y 覆盖(不加则默认询问是否覆盖)
​ -F 生成一个exe文件(不加则生成目录,各种第三方依赖、资源和exe同时存储在该目录)
​ -n 生成的exe文件名(不加则默认.py文件的名字)
​ -i 执行图标
–add-data 添加第三方库文件,有时候打包完发现运行时缺少文件,则需要用此命令。我在项目中用到了mediapipe,结果运行时显示
在这里插入图片描述
添加–add-data后修复,分号前为源地址,分号后为目的地址。(bug修复参考文章:https://blog.csdn.net/xujianjun229/article/details/120049583?spm=1001.2014.3001.5506)

猜你喜欢

转载自blog.csdn.net/qq_42283621/article/details/124205494