用pyinstall打包.py文件

基本方法:

pyinstall -F -w -i ico.ico example.py

具体参数:

General Options

-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)
-y, --noconfirm
  Replace output directory (default: SPECPATH/dist/SPECNAME) without asking for confirmation
--upx-dir UPX_DIR
  Path to UPX utility (default: search the execution path)
-a, --ascii Do not include unicode encoding support (default: included if available)
--clean Clean PyInstaller cache and remove temporary files before building.
--log-level LEVEL
  Amount of detail in build-time console messages. LEVEL may be one of TRACE, DEBUG, INFO, WARN, ERROR, CRITICAL (default: INFO).

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)

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, --debug Tell the bootloader to issue progress messages while initializing and starting the bundled app. Used to diagnose problems with missing imports.
-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)

Windows and Mac OS X specific options

-c, --console, --nowindowed
  Open a console window for standard i/o (default)
-w, --windowed, --noconsole
  Windows and Mac OS X: do not provide a console window for standard i/o. On Mac OS X this also triggers building an OS X .app bundle. This option is ignored in *NIX systems.
-i <FILE.ico or FILE.exe,ID or FILE.icns>, --icon <FILE.ico or FILE.exe,ID or FILE.icns>
  FILE.ico: apply that icon to a Windows executable. FILE.exe,ID, extract the icon with ID from an exe. FILE.icns: apply the icon to the .app bundle on Mac OS X

Windows specific options

--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)
时间: 2024-12-14 05:24:36

用pyinstall打包.py文件的相关文章

pyinstall打包资源文件

相关代码 main.py import sys import os #生成资源文件目录访问路径 #说明: pyinstaller工具打包的可执行文件,运行时sys.frozen会被设置成True # 因此可以通过sys.frozen的值区分是开发环境还是打包后的生成环境 # # 打包后的生产环境,资源文件都放在sys._MEIPASS目录下 # 修改main.spec中的datas, # 如datas=[('res', 'res')],意思是当前目录下的res目录加入目标exe中,在运行时放在零

使用py2exe打包py文件

Step1:下载并安装 py2exe-0.6.9.win32-py2.7.exe和pywin32-217.win32-py2.7.exe(我使用的是Python2.7.3版本) step2: 建文件setup.py.这里setup的参数可以使用windows也可以是console.区别在于你想要在窗口中还是控制台显示. windows后面[]里面的文件可以是任何你想要打包成exe格式的GUI文件. # setup.py from distutils.core import setup impor

pyinstaller打包exe文件闪退的解决办法

pyinstaller是python下目前能打包py文件为windows下的exe文件的一个非常友好易用的库!但是,小爬每次用pyinstaller打包时也总是遇到一些难题,有时网上搜了一圈,也没看到合适的答案.小爬因此决定把我的问题和后来的解决思路都写出来,供后来者参考! 事情是这样的,小爬最近编写了一个发票PDF文件的识别脚本:1.用到PyMuPDF中的fitz模块来提取发票的二维码图片元素:2.用到pyzbar来提取二维码信息:3.用pdfplumber(该库依赖于pdfminer.six

Python如何将py文件打包成exe

安装pyinstaller 打开cmd窗口,输入pip install pyinstaller,命令行输出successfully表示成功. 生成exe文件 一.单个py文件 在py文件目录下,打开cmd窗口,输入pyinstall -F XXX.py,执行成功的话,会在当前目录生成一个dist文件夹,XXX.exe文件在此文件夹下. 添加版本信息: 安装好pyinstaller后,我们会得到两个辅助工具,pyi-grab_version和pyi-set_version. 1. 使用pyi-gr

webService接口的py文件打包成exe

(一)webService接口的py文件打包成exe,在python3.5版本.pyInstaller3.2版本.pywin32-219.win-amd64-py3.5版本打包时报错,原因可能是pyinstaller.py文件使用python2语法写的代码. (二)webService接口的py文件打包成exe,在python2.7版本.pyInstaller2.0版本.pywin32-219.win32-py2.7版本打包成功,并成功运行. 打包步骤: 1.安装pywin32 2.解压缩pyI

将做好的py文件打包成模块,供别人安装调用

现在要将写完的3个py文件,打包. 步骤: 1.新建一个文件夹setup(名字随便取),在setup文件夹下,再新建一个文件夹financeapi. 2.将上面4个py文件拷贝至financeapi文件夹. 3.在setup文件夹下新建一个setup.py文件,里面的内容:详细参见(https://docs.python.org/3/distutils/setupscript.html) 4.打包: 会生成一个dist文件夹,和一个MANIFEST文件.其中dist下面就有你刚才打好的包. 5.

Python3.4 .py文件如何打包成.exe文件

一.安装pywin32 1.下载pywin32-218.win-amd64-py3.4.exe (根据操作系统的位数下载) 2.运行安装 3.如果安装提示如下错误: 打开注册表 "regedit" 1.从"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python"找到注册表,导出 2.编辑其内容,用"HKEY_CURRENT_USER\Software" 替换全部的 "HKEY_LOCAL_MACHI

Python的.py文件打包成exe可执行文件

前几天做了几个简单的爬虫python程序,于是就想做个窗口看看效果. 首先是,窗口的话,以前没怎么接触过,就先考虑用Qt制作简单的ui.这里用前面sinanews的爬虫脚本为例,制作一个获取当天sina头条新闻的窗口. 生成py文件后,运行该py文件,这里窗口我只是随便拖了几个组件进去,主要的text browser用于显示获取到的sinanews. 首先贴一下我的配置(点击即可官方下载):Python 3.3.3 PyQt5-5.2.1 for Py3.3(当安装完Python3.3后,安装对

将py文件打包成exe可执行文件

"""将python代码打包成exe可执行文件 日常生活中,我们可以很轻松的实现,运用编程代码实现我们想要实现的各种功能,解决各种问题,但是如果要将我们编写好的代码给别人使用,如果要他们直接使用我们的代码,就需要安装各种编译软件以及第三方模块,还要对软件操作,编程有一定的了解,这对使用者的要求比较高,不是很方便,为了解决这一问题,我们可以选择将我们编写的代码,编译成一个可执行文件,这样,就可以实现跨平台运行,且避免繁杂的操作,下面,我们来重点介绍这个操作步骤: 下面介绍在py