1. Pyinstaller简介

python脚本如果在没有安装python的机器上不能运行,所以将脚本打包成exe文件,降低脚本对环境的依赖性,同时运行更加迅速。当然打包的脚本似乎不是在所有的win平台下都能使用,win7有一部分不能使用,我在win10能够很好的运行。

PyInstaller库是将.py源代码转换成无需源代码的可执行文件的一个第三方库。

2. 安装方法

pip install pyinstaller

国内建议使用国内源等加快下载速度,使用方式如下:

pip install -i <国内源> pyinstaller

例如:使用豆瓣源

pip install -i https://pypi.douban.com/simple pyinstaller

国内源有清华、阿里、中科大等,可根据自己需求选择

3. 使用方法

pyinstaller  [optional arguments]  positional arguments

参数详解:

positional arguments:即为需要转换的代码源文件,一般为.py结尾的python源代码文件。

optional arguments:

-h, --help----------------------------显示帮助
  -v, --version------------------------显示pyinstaller版本
  --distpath DIR---------------------存放生成exe的位置,默认当前目录下dist文件夹
  --workpath WORKPATH----- --存放.log, .pyz等临时文件目录,默认为当前目录下build文件夹
  -y, --noconfirm--------------------转换后软件的存放目录
  --upx-dir UPX_DIR--------------UPX(用于exe压缩)路径,默认会自动搜索其路径
  -a, --ascii---------------------------不支持unicode编码,默认尽可能支持
  --clean------------------------------创建新程序前清理缓存及临时文件
  --log-level LEVEL----------------日志级别,取值有:TRACE, DEBUG, INFO, WARN, ERROR, CRITICAL,默认为INFO

-D, --onedir-----------------------默认选项,生成包含exe程序的文件夹
  -F, --onefile-----------------------单独生成一个exe文件
  --specpath DIR------------------存放规范文件的路径,默认为当前目录
  -n NAME, --name NAME------转换后exe的名称,默认为脚本名称,例如:run.py转换后默认为run.exe

What to bundle, where to search:
  --add-data <SRC;DEST or SRC:DEST>
                        Additional non-binary files or folders to be added to
                        the executable. The path separator is platform
                        specific, ``os.pathsep`` (which is ``;`` on Windows
                        and ``:`` on most unix systems) is used. This option
                        can be used multiple times.
  --add-binary <SRC;DEST or SRC:DEST>
                        Additional binary files to be added to the executable.
                        See the ``--add-data`` option for more details. This
                        option can be used multiple times.
  -p DIR, --paths DIR   A path to search for imports (like using PYTHONPATH).
                        Multiple paths are allowed, separated by ';', or use
                        this option multiple times
  --hidden-import MODULENAME, --hiddenimport MODULENAME
                        Name an import not visible in the code of the
                        script(s). This option can be used multiple times.
  --additional-hooks-dir HOOKSPATH
                        An additional path to search for hooks. This option
                        can be used multiple times.
  --runtime-hook RUNTIME_HOOKS
                        Path to a custom runtime hook file. A runtime hook is
                        code that is bundled with the executable and is
                        executed before any other code or module to set up
                        special features of the runtime environment. This
                        option can be used multiple times.
  --exclude-module EXCLUDES
                        Optional module or package (the Python name, not the
                        path name) that will be ignored (as though it was not
                        found). This option can be used multiple times.
  --key KEY             The key used to encrypt Python bytecode.

How to generate:
  -d {all,imports,bootloader,noarchive}, --debug {all,imports,bootloader,noarchive}
                        Provide assistance with debugging a frozen
                        application. This argument may be provided multiple
                        times to select several of the following options.

- all: All three of the following options.

- imports: specify the -v option to the underlying
                          Python interpreter, causing it to print a message
                          each time a module is initialized, showing the
                          place (filename or built-in module) from which it
                          is loaded. See
                          https://docs.python.org/3/using/cmdline.html#id4.

- bootloader: tell the bootloader to issue progress
                          messages while initializing and starting the
                          bundled app. Used to diagnose problems with
                          missing imports.

- noarchive: instead of storing all frozen Python
                          source files as an archive inside the resulting
                          executable, store them as files in the resulting
                          output directory.

-s, --strip           Apply a symbol-table strip to the executable and
                        shared libs (not recommended for Windows)
  --noupx               Do not use UPX even if it is available (works
                        differently between Windows and *nix)
  --upx-exclude FILE    Prevent a binary from being compressed when using upx.
                        This is typically used if upx corrupts certain
                        binaries during compression. FILE is the filename of
                        the binary without path. This option can be used
                        multiple times.

Windows和Mac OS X特有选项:
  -c, --console, --nowindowed----------使用windows控制台,此为默认选项
  -w, --windowed, --noconsole----------不使用windows或Mac OS控制台                        
  -i <FILE.ico or FILE.exe,ID or FILE.icns>, --icon <FILE.ico or FILE.exe,ID or FILE
                        FILE.ico: 指定windows exe的图标
                        FILE.exe,ID:根据ID提取指定exe的图标并使用
                        FILE.icns: 指定Mac OS X系统程序图标
Windows特有选项:
  --version-file FILE   add a version resource from FILE to the exe
  -m <FILE or XML>, --manifest <FILE or XML>
                        add manifest FILE or XML to the exe
  -r RESOURCE, --resource RESOURCE
                        Add or update a resource to a Windows executable. The
                        RESOURCE is one to four items,
                        FILE[,TYPE[,NAME[,LANGUAGE]]]. FILE can be a data file
                        or an exe/dll. For data files, at least TYPE and NAME
                        must be specified. LANGUAGE defaults to 0 or may be
                        specified as wildcard * to update all resources of the
                        given TYPE and NAME. For exe/dll files, all resources
                        from FILE will be added/updated to the final
                        executable if TYPE, NAME and LANGUAGE are omitted or
                        specified as wildcard *.This option can be used
                        multiple times.
  --uac-admin           Using this option creates a Manifest which will
                        request elevation upon application restart.
  --uac-uiaccess        Using this option allows an elevated application to
                        work with Remote Desktop.

Windows Side-by-side Assembly searching options (advanced):
  --win-private-assemblies
                        Any Shared Assemblies bundled into the application
                        will be changed into Private Assemblies. This means
                        the exact versions of these assemblies will always be
                        used, and any newer versions installed on user
                        machines at the system level will be ignored.
  --win-no-prefer-redirects
                        While searching for Shared or Private Assemblies to
                        bundle into the application, PyInstaller will prefer
                        not to follow policies that redirect to newer
                        versions, and will try to bundle the exact versions of
                        the assembly.

Mac OS X specific options:
  --osx-bundle-identifier BUNDLE_IDENTIFIER
                        Mac OS X .app bundle identifier is used as the default
                        unique program name for code signing purposes. The
                        usual form is a hierarchical name in reverse DNS
                        notation. For example:
                        com.mycompany.department.appname (default: first
                        script's basename)

Rarely used special options:
  --runtime-tmpdir PATH
                        Where to extract libraries and support files in
                        `onefile`-mode. If this option is given, the
                        bootloader will ignore any temp-folder location
                        defined by the run-time OS. The ``_MEIxxxxxx``-folder
                        will be created here. Please use this option only if
                        you know what you are doing.
  --bootloader-ignore-signals
                        Tell the bootloader to ignore signals rather than
                        forwarding them to the child process. Useful in
                        situations where e.g. a supervisor process signals
                        both the bootloader and child (e.g. via a process
                        group) to avoid signalling the child twice.

使用示例:

python代码转换成EXE文件之pyinstaller使用教程相关推荐

  1. python打包成.exe文件时出现“系统找不到指定路径”

    python打包成.exe文件时出现"系统找不到指定路径" 我在一开始写工程时就想到最后打包的时候可能会出现文件位置会发生移动,所以并没有使用绝对路径,而都是以相对路径写的程序. ...

  2. python如何将图片打包进exe里_史上最详细的Python打包成exe文件教程

    打包成exe文件可以让python代码在没有python环境的条件下,依然能够运行,实在是码农们写追女朋友表白.情人节浪漫的必需品! 1.使用豆瓣镜像源下载: pyinstaller 有需要了解如何使 ...

  3. Python打包成exe文件_详细操作

    Python打包成exe文件 前言 一.安装pyinstaller 1.1 安装pyinstaller,使用安装命令: 1.2 如果遇到需要更新版本请输入: 1.3 检查是否正确安装 1.4 稍等,水 ...

  4. Tips--解决Python打包成exe文件大启动慢的问题

    解决Python打包成exe文件大启动慢的问题 1. 问题描述 2. 产生原因 2. 解决方法 2.1 建立虚拟环境 2.2 安装所需库 2.3 在环境中打包 2.4 附pyinstaller参数表 ...

  5. 把python语言翻译出来_Python语言实现翻译小工具(Python打包成exe文件)

    本文主要向大家介绍了Python语言实现翻译小工具(Python打包成exe文件),通过具体的内容向大家展示,希望对大家学习Python语言有所帮助. 1.环境 windows10 python3.5 ...

  6. python打包成exe文件提示PermissionError: [Errno 13] Permission denied: ‘C:\\Users\\wj\\AppData\\Local\\Progr

    用python写了个脚本给业务部门用,考虑业务部分使用环境问题给打包成exe文件.在打包时提示PermissionError: [Errno 13] Permission denied: 'C:\\U ...

  7. pyinstaller将py文件打包成EXE文件(保姆级教程)

    一.PyInstaller 库的安装 1.一般安装步骤: pip install pyinstaller一般的安装方法是在cmd命令提示符环境下输入: window+r 运行cmd 输入以下内容切换到 ...

  8. python打包成exe文件大、执行慢_Pyinstaller打包exe太大,运行太慢

    1.背景 通过python使用pyqt编写了一个界面程序,并使用pyinstaller将其打包成exe文件 2.问题 打包的exe文件非常大,有280M,而且更无法忍受的是打开非常非常的慢!!! 3. ...

  9. 将python打包成exe文件(携带附属文件)

    前言 用Pyinstaller进行打包exe时,有时候得附带上一些资源,提高程序的实用性和人性化. 在网上也有很多把依赖文件打包进exe的方法,不过都只能打包一些图片或者文本而已. 另一种方法是通过修 ...

  10. 解决 Python打包成exe 文件过大问题的一些方法

    前言 之前有做过Python的pyqt桌面应用,当时每次更新打包的时候整个文件下来都需要300~400M,但是一直没有找到合适的方法解决,而是尽量Python少安抓库包,但效果一般,最近找到了解决方法 ...

最新文章

  1. ubuntu pip
  2. C++环境测试CPU是否支持MMX,SSE-未完
  3. 基于ISE的设计实现基础
  4. 机器学习从零开始-常见算法手推pure python
  5. linux tomcat8 启动慢,Linux系统下Tomcat8启动速度很慢的解决方法
  6. 一起谈.NET技术,HubbleDotNet 和 Lucene.Net 匹配相关度的比较
  7. mlock家族:锁定物理内存
  8. compareto方法_Java ArrayList 的不同排序方法
  9. Xcode :error: linker command failed with exit code 1(use -v to see invocation) 或 libstdc++.6.0缺失问题
  10. YAML文件格式详解
  11. 内容分发网络(CDN)
  12. KVM或openstack虚拟化环境中windows主机忘记登陆密码如何使用pe的方式进行破解
  13. python中py是什么意思_python中__init__.py是干什么的
  14. 利用AI+大数据的方式分析恶意样本(十三)
  15. 英国招生官建议个人陈述该做些什么
  16. su与su - 命令详解
  17. pythonweb全栈开发_Python web全栈学习路线
  18. 完成GitHub上squirrel 的运行(数据库的模糊测试)
  19. C语言结构标记的作用,C语言基础知识之词法符号
  20. ubuntu20.04安装企业微信

热门文章

  1. outlook配置文件添加服务器,Microsoft Outlook卡在加载配置文件?这里如何解决它
  2. 浪潮4U服务器 raid5 直通(JBOD)
  3. 计算机硬件设备ppt教案,《计算机硬件基础》PPT课件.ppt
  4. 原笔迹手写实现平滑和笔锋效果之:笔迹的平滑(一)
  5. c语言贪吃蛇游戏视频,贪吃蛇游戏,贪吃蛇游戏视频
  6. html五线谱编辑器,​Notation Pad五线谱乐谱编辑器
  7. Premiere CS4无法导出视频
  8. Objective C转Swift注意事项(一)合理使用结构体,枚举,extensions
  9. 破除对 AWS Fargate 的幻觉
  10. Power bi 4.20 词云