zoukankan      html  css  js  c++  java
  • Python pyinstaller

    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

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

     


    2、输入参数的含义

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

    三、注意事项

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

     

     


    在打包之前务必找到第三方库的包,把包复制到跟 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

  • 相关阅读:
    Lua 的元表怎么理解
    Lua中的元表与元方法
    Lua 的元表怎么理解
    VMware Workstation 系统备份-虚拟机克隆方法
    Lua中的元表与元方法
    bzoj2809
    bzoj2733
    bzoj1334
    bzoj1211
    bzoj3083 3306
  • 原文地址:https://www.cnblogs.com/emanlee/p/15807421.html
Copyright © 2011-2022 走看看