python3.6.2利用pyinstaller发布EXE

    我的环境是Ubuntu 16.04,系统自带Python2和Python3

安装

pip3 install pyinstaller

发布exe

pyinstaller -F helloworld.py

其中,-F 表示打包成单独的 .exe 文件,这时生成的 .exe 文件会比较大,而且运行速度回较慢。仅仅一个 helloworld 程序,生成的文件就 5MB 大。

另外,使用 -i 还可以指定可执行文件的图标; -w 表示去掉控制台窗口,这在 GUI 界面时非常有用。不过如果是命令行程序的话那就把这个选项删除吧!

PyInstaller 会对脚本进行解析,并做出如下动作:

  1. 在脚本目录生成 helloworld.spec 文件;
  2. 创建一个 build 目录;
  3. 写入一些日志文件和中间流程文件到 build 目录;
  4. 创建 dist 目录;
  5. 生成可执行文件到 dist 目录;

注意

我在第一次执行上一操作的时候是报错的,报错内容如下:
AttributeError: 'str' object has no attribute 'items'
在网上搜寻答案,在stackoverflow上找到了答案,原来是我的工具没安装完全,下面是帖子原文链接:
https://stackoverflow.com/questions/35613300/pyinstaller-compile-to-exe

 执行以下命令:

pip3 install --upgrade setuptools

再继续上面的第二步,一个exe就生成好了。

参考链接:

 1. https://www.jianshu.com/p/9a4ca50d08af

 2. https://zhuanlan.zhihu.com/p/45288707

猜你喜欢

转载自www.cnblogs.com/lfri/p/10745783.html