pyinstaller的安装及使用_03

安装pyinstaller

pip install pyinstaller

或升级到较新版本:

pip install --upgrade pyinstaller

验证安装
pyinstaller --version

  • 注意

  1. Warning : 未将 'C:...\PythonXY\Scripts' 路径添加至环境变量(其中XY代表主要和次要Python版本号),将路径添加至PATH即可,重启PowerShell或cmd工具再次尝试验证安装。
  2. Warning : pip有新版本可用 ,将警告中的更新命令粘贴执行即可,使用pip --version命令查看pip版本或pip show pip命令查看pip详细信息。

使用pyinstaller导出py脚本为exe程序

pyinstaller -F scriptName.py


  • The syntax of the command is:
    pyinstaller [options] script [script …] | specfile
    In the most simple case, set the current directory to the location of your program and execute: scriptName.py

  • Optional Arguments
    -h, --help
    show this help message and exit
    -v, --version
    Show program version info and exit.
    --distpath DIR
    Where to put the bundled app (default: ./dist)
    --workpath WORKPATH
    Where to put all the temporary work files, .log, .pyz and etc. (default: ./build)

  • What To Generate
    -D, --onedir
    Create a one-folder bundle containing an executable (default)
    -F, --onefile
    Create a one-file bundled executable.
    --specpath DIR
    Folder to store the generated spec file (default: current directory)
    -n NAME, --name NAME
    Name to assign to the bundled app and spec file (default: first script’s basename)

  • Windows And Mac Os X Specific Options
    -c, --console, --nowindowed
    Open a console window for standard i/o (default). On Windows this option has no effect if the first script is a ‘.pyw’ file.
    -w, --windowed, --noconsole
    Windows and Mac OS X: do not provide a console window for standard i/o. On Mac OS this also triggers building a Mac OS .app bundle. On Windows this option is automatically set if the first script is a ‘.pyw’ file. This option is ignored on *NIX systems.

  • Running PyInstaller from Python code
    If you want to run PyInstaller from Python code, you can use the function defined in . For instance, the following code:

    import PyInstaller.__main__
    
    PyInstaller.__main__.run([
        'my_script.py',
        '--onefile',
        '--windowed'
    ])
    

    Is equivalent to:
    pyinstaller my_script.py --onefile --windowed


参考博客或网址:

如何安装 PyInstaller
使用 PyInstaller

posted @ 2022-08-10 11:22  Ganders  阅读(508)  评论(0编辑  收藏  举报