微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Python pyinstaller.exe 使用入门

Python pyinstaller

Python 认并不包含 PyInstaller 模块,因此需要自行安装 PyInstaller 模块。

 一、安装 Pyinstaller

安装 Pyinstaller
        官网  http://www.pyinstaller.org/
        使用pip命令安装:pip install pyinstaller

 

安装之后,会有 pyinstaller.exe

 

 

D:\Program Files\python_3_6_4\Scripts>pip show pyinstaller
Name: pyinstaller
Version: 4.8
Summary: PyInstaller bundles a Python application and all its dependencies into a single package.
Home-page: http://www.pyinstaller.org/
Author: Hartmut Goebel, Giovanni Bajo, David Vierra, David Cortesi, Martin Zibricky
Author-email:
License: GPLv2-or-later with a special exception which allows to use PyInstaller to build and distribute non-free programs (including commercial ones)
Location: d:\program files\python_3_6_4\lib\site-packages
Requires: altgraph, importlib-Metadata, pefile, pyinstaller-hooks-contrib, pywin32-ctypes, setuptools
required-by:

 

把 pyinstaller.exe 的路径加到系统的环境变量的 path 里面,以后在 cmd 窗口可以使用。

 

 

 
二、使用Pyinstaller

1、 打开 cmd 窗口,把路径切换到文件所在路径(文件随便放在哪里都行)打开命令提示行,输入以下内容(最后的是文件名):

        cd  D:\temp-test\RecordScreen
        pyinstaller -F division_test.py

如果程序有GUI界面,使用: pyinstaller.exe -F -w tkinteraddminus.py

 

生成两个文件夹 build 和 dist , 生成的 exe 在 dist 中。

 

 

 

 


2、输入参数的含义

    -F 表示生成单个可执行文件( -D 多个文件)。
    -w 表示去掉控制台窗口,这在GUI界面时非常有用。不过如果是命令行程序的话那就把这个选项删除吧。
    -p 表示你自己自定义需要加载的类路径,一般情况下用不到。
    -i 表示可执行文件的图标。

三、注意事项
py 文件编码为 UTF-8,否则出错

 

文件中使用了第三方库的打包方式

 

 

 

 


在打包之前务必找到第三方库的包,把包复制到跟 division_test.py  同目录下,然后再打包,否则会打包失败或者即使打包成功,程序也会闪退。

 
给程序换图标的方法
            输入命令中添加一个 -i tubiao.ico (图标的相对路径)。

四、exe文件生成

    如果程序打包过程没有报错,则会生成3个文件夹(有时候是2个),其中名为 dist 的文件夹中会有一个 division_test.exe 文件,运行一下,如果没有问题就打包成功,可以把这个exe文件单独拿出去用,其他的生成文件夹可以删掉了。

  

 PyCharm中配置Pyinstaller

 

 如何打包成32位程序:

 安装 python3.5 32位的,是因为 pyinstaller 32位的包好像支持到3.5,如果使用python3.6或3.7安装pyinstaller 32位会报错。

  

REF
http://www.cnblogs.com/goPythoner/p/6337543.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐