加入收藏 | 设为首页 | 会员中心 | 我要投稿 汽车网 (https://www.0577qiche.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 教程 > 正文

Python pyinstaller.exe 使用入门

发布时间:2023-04-11 11:16:13 所属栏目:教程 来源:
导读:Python pyinstaller

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

一、安装 Pyinstaller

安装 Pyinstaller
使用pip命令安装:pip install pyinstaller

安装之
Python pyinstaller

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

 一、安装 Pyinstaller

安装 Pyinstaller
        使用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: 
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位会报错。

(编辑:汽车网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章