- Python : 3.8.13
- OS : Windows 21H1
- Conda : 4.12.0
- PyCharm : 2022.1 (Community Edition)
pip安装pyinstaller
C:\Users\admin\PycharmProjects\pythonProject1>conda activate pyqtenv
(pyqtenv) C:\Users\admin\PycharmProjects\pythonProject1>pip install pyinstaller
Collecting pyinstaller
Downloading pyinstaller-5.0.1-py3-none-win_amd64.whl (2.0 MB)
|████████████████████████████████| 2.0 MB 595 kB/s
Collecting altgraph
Downloading altgraph-0.17.2-py2.py3-none-any.whl (21 kB)
Collecting pywin32-ctypes>=0.2.0
Downloading pywin32_ctypes-0.2.0-py2.py3-none-any.whl (28 kB)
Requirement already satisfied: setuptools in d:\develop\anaconda3\envs\pyqtenv\lib\site-packages (from pyinstaller) (61.2.0)
Collecting pefile>=2017.8.1
Downloading pefile-2021.9.3.tar.gz (72 kB)
|████████████████████████████████| 72 kB 119 kB/s
Collecting pyinstaller-hooks-contrib>=2020.6
Downloading pyinstaller_hooks_contrib-2022.4-py2.py3-none-any.whl (229 kB)
|████████████████████████████████| 229 kB 726 kB/s
Collecting future
Downloading future-0.18.2.tar.gz (829 kB)
|████████████████████████████████| 829 kB 1.6 MB/s
Building wheels for collected packages: pefile, future
Building wheel for pefile (setup.py) ... done
Created wheel for pefile: filename=pefile-2021.9.3-py3-none-any.whl size=68846 sha256=11d97347a2babb5263c347770b44aac5a1c8d3162f4bbd6ba0d05b0a2419e6c2
Stored in directory: c:\users\admin\appdata\local\pip\cache\wheels\ee\a0\e1\ff2dafe5ae846f536acf0a4cc4a8b8d4ccb3044ab87f3ef174
Building wheel for future (setup.py) ... done
Created wheel for future: filename=future-0.18.2-py3-none-any.whl size=491070 sha256=4b7b8acfde7fbf35129cdcde6a7cfe34eb9d3fb822cbe99c3c9397cd22e8639f
Stored in directory: c:\users\admin\appdata\local\pip\cache\wheels\8e\70\28\3d6ccd6e315f65f245da085482a2e1c7d14b90b30f239e2cf4
Successfully built pefile future
Installing collected packages: future, pywin32-ctypes, pyinstaller-hooks-contrib, pefile, altgraph, pyinstaller
Successfully installed altgraph-0.17.2 future-0.18.2 pefile-2021.9.3 pyinstaller-5.0.1 pyinstaller-hooks-contrib-2022.4 pywin32-ctypes-0.2.0
(pyqtenv) C:\Users\admin\PycharmProjects\pythonProject1>
UI界面
文件结构
(pyqtenv) C:\Users\admin\PycharmProjects\pythonProject1>tree /F
文件夹 PATH 列表
卷序列号为 B0D5-61C1
C:.
│ demo.py
│ main.py
│ untitled.py
│ untitled.ui
│
├─.idea
│ │ .gitignore
│ │ misc.xml
│ │ modules.xml
│ │ pythonProject1.iml
│ │ workspace.xml
│ │
│ └─inspectionProfiles
│ profiles_settings.xml
│
└─__pycache__
untitled.cpython-38.pyc
代码
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'untitled.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(428, 342)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(160, 110, 81, 31))
self.pushButton.setObjectName("pushButton")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 428, 23))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "PushButton"))
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
import untitled
if __name__ == '__main__':
app = QApplication(sys.argv)
window = QMainWindow()
ui = untitled.Ui_MainWindow()
ui.setupUi(window)
window.show()
sys.exit(app.exec_())
效果-pycharm
pyinstaller使用默认值进行打包
(pyqtenv) C:\Users\admin\PycharmProjects\pythonProject1>pyinstaller main.py
396 INFO: PyInstaller: 5.0.1
397 INFO: Python: 3.8.13 (conda)
408 INFO: Platform: Windows-10-10.0.19043-SP0
409 INFO: wrote C:\Users\admin\PycharmProjects\pythonProject1\main.spec
411 INFO: UPX is not available.
412 INFO: Extending PYTHONPATH with paths
['C:\\Users\\admin\\PycharmProjects\\pythonProject1']
665 INFO: checking Analysis
666 INFO: Building Analysis because Analysis-00.toc is non existent
666 INFO: Initializing module dependency graph...
668 INFO: Caching module graph hooks...
680 INFO: Analyzing base_library.zip ...
2966 INFO: Processing pre-find module path hook distutils from 'D:\\Develop\\Anaconda3\\envs\\pyqtenv\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
2967 INFO: distutils: retargeting to non-venv dir 'D:\\Develop\\Anaconda3\\envs\\pyqtenv\\lib'
5268 INFO: Caching module dependency graph...
5436 INFO: running Analysis Analysis-00.toc
5455 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by D:\Develop\Anaconda3\envs\pyqtenv\python.exe
5786 INFO: Analyzing C:\Users\admin\PycharmProjects\pythonProject1\main.py
5812 INFO: Processing module hooks...
5812 INFO: Loading module hook 'hook-difflib.py' from 'D:\\Develop\\Anaconda3\\envs\\pyqtenv\\lib\\site-packages\\PyInstaller\\hooks'...
5815 INFO: Loading module hook 'hook-distutils.py' from 'D:\\Develop\\Anaconda3\\envs\\pyqtenv\\lib\\site-packages\\PyInstaller\\hooks'...
5815 INFO: Loading module hook 'hook-distutils.util.py' from 'D:\\Develop\\Anaconda3\\envs\\pyqtenv\\lib\\site-packages\\PyInstaller\\hooks'...
5816 INFO: Loading module hook 'hook-encodings.py' from 'D:\\Develop\\Anaconda3\\envs\\pyqtenv\\lib\\site-packages\\PyInstaller\\hooks'...
5880 INFO: Loading module hook 'hook-heapq.py' from 'D:\\Develop\\Anaconda3\\envs\\pyqtenv\\lib\\site-packages\\PyInstaller\\hooks'...
5882 INFO: Loading module hook 'hook-lib2to3.py' from 'D:\\Develop\\Anaconda3\\envs\\pyqtenv\\lib\\site-packages\\PyInstaller\\hooks'...
5929 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'D:\\Develop\\Anaconda3\\envs\\pyqtenv\\lib\\site-packages\\PyInstaller\\hooks'...
5931 INFO: Loading module hook 'hook-pickle.py' from 'D:\\Develop\\Anaconda3\\envs\\pyqtenv\\lib\\site-packages\\PyInstaller\\hooks'...
5932 INFO: Loading module hook 'hook-PyQt5.py' from 'D:\\Develop\\Anaconda3\\envs\\pyqtenv\\lib\\site-packages\\PyInstaller\\hooks'...
6068 WARNING: Hidden import "sip" not found!
6069 INFO: Loading module hook 'hook-PyQt5.QtCore.py' from 'D:\\Develop\\Anaconda3\\envs\\pyqtenv\\lib\\site-packages\\PyInstaller\\hooks'...
6244 INFO: Loading module hook 'hook-PyQt5.QtGui.py' from 'D:\\Develop\\Anaconda3\\envs\\pyqtenv\\lib\\site-packages\\PyInstaller\\hooks'...
6545 INFO: Loading module hook 'hook-PyQt5.QtWidgets.py' from 'D:\\Develop\\Anaconda3\\envs\\pyqtenv\\lib\\site-packages\\PyInstaller\\hooks'...
6972 INFO: Loading module hook 'hook-sysconfig.py' from 'D:\\Develop\\Anaconda3\\envs\\pyqtenv\\lib\\site-packages\\PyInstaller\\hooks'...
6973 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'D:\\Develop\\Anaconda3\\envs\\pyqtenv\\lib\\site-packages\\PyInstaller\\hooks'...
6976 INFO: Loading module hook 'hook-xml.py' from 'D:\\Develop\\Anaconda3\\envs\\pyqtenv\\lib\\site-packages\\PyInstaller\\hooks'...
7054 INFO: Loading module hook 'hook-_tkinter.py' from 'D:\\Develop\\Anaconda3\\envs\\pyqtenv\\lib\\site-packages\\PyInstaller\\hooks'...
7198 INFO: checking Tree
7198 INFO: Building Tree because Tree-00.toc is non existent
7199 INFO: Building Tree Tree-00.toc
7345 INFO: checking Tree
7345 INFO: Building Tree because Tree-01.toc is non existent
7346 INFO: Building Tree Tree-01.toc
7423 INFO: checking Tree
7423 INFO: Building Tree because Tree-02.toc is non existent
7424 INFO: Building Tree Tree-02.toc
7445 INFO: Looking for ctypes DLLs
7459 INFO: Analyzing run-time hooks ...
7462 INFO: Including run-time hook 'D:\\Develop\\Anaconda3\\envs\\pyqtenv\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_subprocess.py'
7463 INFO: Including run-time hook 'D:\\Develop\\Anaconda3\\envs\\pyqtenv\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgutil.py'
7465 INFO: Including run-time hook 'D:\\Develop\\Anaconda3\\envs\\pyqtenv\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
7468 INFO: Including run-time hook 'D:\\Develop\\Anaconda3\\envs\\pyqtenv\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_inspect.py'
7470 INFO: Including run-time hook 'D:\\Develop\\Anaconda3\\envs\\pyqtenv\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pyqt5.py'
7475 INFO: Looking for dynamic libraries
9048 INFO: Looking for eggs
9049 INFO: Using Python library D:\Develop\Anaconda3\envs\pyqtenv\python38.dll
9050 INFO: Found binding redirects:
[]
9054 INFO: Warnings written to C:\Users\admin\PycharmProjects\pythonProject1\build\main\warn-main.txt
9099 INFO: Graph cross-reference written to C:\Users\admin\PycharmProjects\pythonProject1\build\main\xref-main.html
9117 INFO: checking PYZ
9117 INFO: Building PYZ because PYZ-00.toc is non existent
9118 INFO: Building PYZ (ZlibArchive) C:\Users\admin\PycharmProjects\pythonProject1\build\main\PYZ-00.pyz
9554 INFO: Building PYZ (ZlibArchive) C:\Users\admin\PycharmProjects\pythonProject1\build\main\PYZ-00.pyz completed successfully.
9563 INFO: checking PKG
9563 INFO: Building PKG because PKG-00.toc is non existent
9564 INFO: Building PKG (CArchive) main.pkg
9577 INFO: Building PKG (CArchive) main.pkg completed successfully.
9578 INFO: Bootloader D:\Develop\Anaconda3\envs\pyqtenv\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
9578 INFO: checking EXE
9578 INFO: Building EXE because EXE-00.toc is non existent
9579 INFO: Building EXE from EXE-00.toc
9579 INFO: Copying bootloader EXE to C:\Users\admin\PycharmProjects\pythonProject1\build\main\main.exe.notanexecutable
9632 INFO: Copying icon to EXE
9632 INFO: Copying icons from ['D:\\Develop\\Anaconda3\\envs\\pyqtenv\\lib\\site-packages\\PyInstaller\\bootloader\\images\\icon-console.ico']
9633 INFO: Writing RT_GROUP_ICON 0 resource with 104 bytes
9633 INFO: Writing RT_ICON 1 resource with 3752 bytes
9635 INFO: Writing RT_ICON 2 resource with 2216 bytes
9635 INFO: Writing RT_ICON 3 resource with 1384 bytes
9635 INFO: Writing RT_ICON 4 resource with 37019 bytes
9636 INFO: Writing RT_ICON 5 resource with 9640 bytes
9636 INFO: Writing RT_ICON 6 resource with 4264 bytes
9637 INFO: Writing RT_ICON 7 resource with 1128 bytes
9685 INFO: Copying 0 resources to EXE
9685 INFO: Embedding manifest in EXE
9687 INFO: Updating manifest in C:\Users\admin\PycharmProjects\pythonProject1\build\main\main.exe.notanexecutable
9687 INFO: Updating resource type 24 name 1 language 0
9727 INFO: Appending PKG archive to EXE
10502 INFO: Building EXE from EXE-00.toc completed successfully.
10505 INFO: checking COLLECT
10505 INFO: Building COLLECT because COLLECT-00.toc is non existent
10505 INFO: Building COLLECT COLLECT-00.toc
14697 INFO: Building COLLECT COLLECT-00.toc completed successfully.
(pyqtenv) C:\Users\admin\PycharmProjects\pythonProject1>
查看打包后的新目录树
- 这里边的文件都是很讲究的,感兴趣的同学可以深入研究一下!
C:\Users\admin\PycharmProjects\pythonProject1>tree /F
文件夹 PATH 列表
卷序列号为 B0D5-61C1
C:.
│ demo.py
│ main.py
│ main.spec
│ untitled.py
│ untitled.ui
│
├─.idea
│ │ .gitignore
│ │ misc.xml
│ │ modules.xml
│ │ pythonProject1.iml
│ │ workspace.xml
│ │
│ └─inspectionProfiles
│ profiles_settings.xml
│
├─build
│ └─main
│ Analysis-00.toc
│ base_library.zip
│ COLLECT-00.toc
│ EXE-00.toc
│ main.exe
│ main.exe.manifest
│ main.pkg
│ PKG-00.toc
│ PYZ-00.pyz
│ PYZ-00.toc
│ Tree-00.toc
│ Tree-01.toc
│ Tree-02.toc
│ warn-main.txt
│ xref-main.html
│
├─dist
│ └─main
│ │ api-ms-win-core-console-l1-1-0.dll
│ │ api-ms-win-core-datetime-l1-1-0.dll
│ │ api-ms-win-core-debug-l1-1-0.dll
│ │ api-ms-win-core-errorhandling-l1-1-0.dll
│ │ api-ms-win-core-file-l1-1-0.dll
│ │ api-ms-win-core-file-l1-2-0.dll
│ │ api-ms-win-core-file-l2-1-0.dll
│ │ api-ms-win-core-handle-l1-1-0.dll
│ │ api-ms-win-core-heap-l1-1-0.dll
│ │ api-ms-win-core-interlocked-l1-1-0.dll
│ │ api-ms-win-core-libraryloader-l1-1-0.dll
│ │ api-ms-win-core-localization-l1-2-0.dll
│ │ api-ms-win-core-memory-l1-1-0.dll
│ │ api-ms-win-core-namedpipe-l1-1-0.dll
│ │ api-ms-win-core-processenvironment-l1-1-0.dll
│ │ api-ms-win-core-processthreads-l1-1-0.dll
│ │ api-ms-win-core-processthreads-l1-1-1.dll
│ │ api-ms-win-core-profile-l1-1-0.dll
│ │ api-ms-win-core-rtlsupport-l1-1-0.dll
│ │ api-ms-win-core-string-l1-1-0.dll
│ │ api-ms-win-core-synch-l1-1-0.dll
│ │ api-ms-win-core-synch-l1-2-0.dll
│ │ api-ms-win-core-sysinfo-l1-1-0.dll
│ │ api-ms-win-core-timezone-l1-1-0.dll
│ │ api-ms-win-core-util-l1-1-0.dll
│ │ api-ms-win-crt-conio-l1-1-0.dll
│ │ api-ms-win-crt-convert-l1-1-0.dll
│ │ api-ms-win-crt-environment-l1-1-0.dll
│ │ api-ms-win-crt-filesystem-l1-1-0.dll
│ │ api-ms-win-crt-heap-l1-1-0.dll
│ │ api-ms-win-crt-locale-l1-1-0.dll
│ │ api-ms-win-crt-math-l1-1-0.dll
│ │ api-ms-win-crt-process-l1-1-0.dll
│ │ api-ms-win-crt-runtime-l1-1-0.dll
│ │ api-ms-win-crt-stdio-l1-1-0.dll
│ │ api-ms-win-crt-string-l1-1-0.dll
│ │ api-ms-win-crt-time-l1-1-0.dll
│ │ api-ms-win-crt-utility-l1-1-0.dll
│ │ base_library.zip
│ │ d3dcompiler_47.dll
│ │ libcrypto-1_1-x64.dll
│ │ libEGL.dll
│ │ libffi-7.dll
│ │ libGLESv2.dll
│ │ libssl-1_1-x64.dll
│ │ main.exe
│ │ MSVCP140.dll
│ │ MSVCP140_1.dll
│ │ opengl32sw.dll
│ │ pyexpat.pyd
│ │ python3.dll
│ │ python38.dll
│ │ Qt5Core.dll
│ │ Qt5DBus.dll
│ │ Qt5Gui.dll
│ │ Qt5Network.dll
│ │ Qt5Qml.dll
│ │ Qt5QmlModels.dll
│ │ Qt5Quick.dll
│ │ Qt5Svg.dll
│ │ Qt5WebSockets.dll
│ │ Qt5Widgets.dll
│ │ select.pyd
│ │ ucrtbase.dll
│ │ unicodedata.pyd
│ │ VCRUNTIME140.dll
│ │ VCRUNTIME140_1.dll
│ │ _asyncio.pyd
│ │ _bz2.pyd
│ │ _ctypes.pyd
│ │ _decimal.pyd
│ │ _hashlib.pyd
│ │ _lzma.pyd
│ │ _multiprocessing.pyd
│ │ _overlapped.pyd
│ │ _queue.pyd
│ │ _socket.pyd
│ │ _ssl.pyd
│ │
│ └─PyQt5
│ │ QtCore.pyd
│ │ QtGui.pyd
│ │ QtWidgets.pyd
│ │ sip.cp38-win_amd64.pyd
│ │
│ └─Qt5
│ ├─plugins
│ │ ├─iconengines
│ │ │ qsvgicon.dll
│ │ │
│ │ ├─imageformats
│ │ │ qgif.dll
│ │ │ qicns.dll
│ │ │ qico.dll
│ │ │ qjpeg.dll
│ │ │ qsvg.dll
│ │ │ qtga.dll
│ │ │ qtiff.dll
│ │ │ qwbmp.dll
│ │ │ qwebp.dll
│ │ │
│ │ ├─platforms
│ │ │ qminimal.dll
│ │ │ qoffscreen.dll
│ │ │ qwebgl.dll
│ │ │ qwindows.dll
│ │ │
│ │ ├─platformthemes
│ │ │ qxdgdesktopportal.dll
│ │ │
│ │ └─styles
│ │ qwindowsvistastyle.dll
│ │
│ └─translations
│ qtbase_ar.qm
│ qtbase_bg.qm
│ qtbase_ca.qm
│ qtbase_cs.qm
│ qtbase_da.qm
│ qtbase_de.qm
│ qtbase_en.qm
│ qtbase_es.qm
│ qtbase_fi.qm
│ qtbase_fr.qm
│ qtbase_gd.qm
│ qtbase_he.qm
│ qtbase_hu.qm
│ qtbase_it.qm
│ qtbase_ja.qm
│ qtbase_ko.qm
│ qtbase_lv.qm
│ qtbase_pl.qm
│ qtbase_ru.qm
│ qtbase_sk.qm
│ qtbase_tr.qm
│ qtbase_uk.qm
│ qtbase_zh_TW.qm
│
└─__pycache__
untitled.cpython-38.pyc
C:\Users\admin\PycharmProjects\pythonProject1>
EXE程序的运行效果
后续优化
- 直接窗口,无控制台,可以加 -w
pyinstaller -w main.py
- 打包成单体exe的形式,可以加 -Fw
pyinstaller -Fw main.py
- 帮助文档中有许多常用参数,建议阅读
(pyqtenv) C:\Users\admin\PycharmProjects\pythonProject1>pyinstaller -h
usage: pyinstaller [-h] [-v] [-D] [-F] [--specpath DIR] [-n NAME] [--add-data <SRC;DEST or SRC:DEST>]
[--add-binary <SRC;DEST or SRC:DEST>] [-p DIR] [--hidden-import MODULENAME]
[--collect-submodules MODULENAME] [--collect-data MODULENAME] [--collect-binaries MODULENAME]
[--collect-all MODULENAME] [--copy-metadata PACKAGENAME] [--recursive-copy-metadata PACKAGENAME]
[--additional-hooks-dir HOOKSPATH] [--runtime-hook RUNTIME_HOOKS] [--exclude-module EXCLUDES]
[--key KEY] [--splash IMAGE_FILE] [-d {all,imports,bootloader,noarchive}]
[--python-option PYTHON_OPTION] [-s] [--noupx] [--upx-exclude FILE] [-c] [-w]
[-i <FILE.ico or FILE.exe,ID or FILE.icns or Image or "NONE">] [--disable-windowed-traceback]
[--version-file FILE] [-m <FILE or XML>] [--no-embed-manifest] [-r RESOURCE] [--uac-admin]
[--uac-uiaccess] [--win-private-assemblies] [--win-no-prefer-redirects] [--argv-emulation]
[--osx-bundle-identifier BUNDLE_IDENTIFIER] [--target-architecture ARCH]
[--codesign-identity IDENTITY] [--osx-entitlements-file FILENAME] [--runtime-tmpdir PATH]
[--bootloader-ignore-signals] [--distpath DIR] [--workpath WORKPATH] [-y] [--upx-dir UPX_DIR] [-a]
[--clean] [--log-level LEVEL]
scriptname [scriptname ...]
positional arguments:
scriptname Name of scriptfiles to be processed or exactly one .spec file. If a .spec file is specified,
most options are unnecessary and are ignored.
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)
-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. Equivalent to supplying the ``pathex`` argument in
the spec file.
--hidden-import MODULENAME, --hiddenimport MODULENAME
Name an import not visible in the code of the script(s). This option can be used multiple
times.
--collect-submodules MODULENAME
Collect all submodules from the specified package or module. This option can be used multiple
times.
--collect-data MODULENAME, --collect-datas MODULENAME
Collect all data from the specified package or module. This option can be used multiple times.
--collect-binaries MODULENAME
Collect all binaries from the specified package or module. This option can be used multiple
times.
--collect-all MODULENAME
Collect all submodules, data files, and binaries from the specified package or module. This
option can be used multiple times.
--copy-metadata PACKAGENAME
Copy metadata for the specified package. This option can be used multiple times.
--recursive-copy-metadata PACKAGENAME
Copy metadata for the specified package and all its dependencies. 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.
--splash IMAGE_FILE (EXPERIMENTAL) Add an splash screen with the image IMAGE_FILE to the application. The splash
screen can display progress updates while unpacking.
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.
--python-option PYTHON_OPTION
Specify a command-line option to pass to the Python interpreter at runtime. Currently supports
"v" (equivalent to "--debug imports"), "u", and "W <warning control>".
-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 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.
-i <FILE.ico or FILE.exe,ID or FILE.icns or Image or "NONE">, --icon <FILE.ico or FILE.exe,ID or FILE.icns or Image or "NONE">
FILE.ico: apply the 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. If an image file is entered
that isn't in the platform format (ico on Windows, icns on Mac), PyInstaller tries to use
Pillow to translate the icon into the correct format (if Pillow is installed). Use "NONE" to
not apply any icon, thereby making the OS show some default (default: apply PyInstaller's
icon)
--disable-windowed-traceback
Disable traceback dump of unhandled exception in windowed (noconsole) mode (Windows and macOS
only), and instead display a message that this feature is disabled.
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.
--no-embed-manifest Generate an external .exe.manifest file instead of embedding the manifest into the exe.
Applicable only to onedir mode; in onefile mode, the manifest is always embedded, regardless
of this option.
-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 that will request elevation upon application start.
--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 specific options:
--argv-emulation Enable argv emulation for macOS app bundles. If enabled, the intial open document/URL event is
processed by the bootloader and the passed file paths or URLs are appended to sys.argv.
--osx-bundle-identifier BUNDLE_IDENTIFIER
Mac OS .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)
--target-architecture ARCH, --target-arch ARCH
Target architecture (macOS only; valid values: x86_64, arm64, universal2). Enables switching
between universal2 and single-arch version of frozen application (provided python installation
supports the target architecture). If not target architecture is not specified, the current
running architecture is targeted.
--codesign-identity IDENTITY
Code signing identity (macOS only). Use the provided identity to sign collected binaries and
generated executable. If signing identity is not provided, ad-hoc signing is performed
instead.
--osx-entitlements-file FILENAME
Entitlements file to use when code-signing the collected binaries (macOS only).
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 for example a supervisor process signals both the bootloader and the child
(e.g., via a process group) to avoid signalling the child twice.
学习推荐
- QT
- PyQt
- PyQt5 - Docs
- Python文档 - English
- Python文档 - 中文
- Python规范 PEP
- Python规范 google版
- Python 源码
- Python PEP
- 掘金平台
- gitee平台
Python具有开源、跨平台、解释型和交互式等特性,值得学习。
Python的设计哲学:优雅,明确,简单。提倡用一种方法,最好是只有一种方法来做一件事。
GUI可以选择Tkinter、PySide2、wxPython、PyGObject、wxWidgets等进行创作。
代码的书写要遵守规范,这样有助于沟通和理解。
每种语言都有独特的思想,初学者需要转变思维、踏实践行、坚持积累。