python中pyinstaller库的使用
使用pyinstaller打包python程序为exe文件
安装pyinstaller库
1 |
pip install pyinstaller |
拿一个我以前写过的简单项目来测试打包
以前的项目结构如下
安装完成之后看到如下界面
在虚拟环境下面运行如下命令
1 |
(axfenv) lizhonglindeMacBook-Pro:stuflask lizhonglin$ pyinstaller -F manage.py |
会得到如下结果就说明打包成功
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
(axfenv) lizhonglindeMacBook-Pro:stuflask lizhonglin$ pyinstaller -F manage.py 48 INFO: PyInstaller: 3.4 48 INFO: Python: 3.6.5 63 INFO: Platform: Darwin-16.7.0-x86_64-i386-64bit 64 INFO: wrote /Users/lizhonglin/Desktop/stuflask/manage.spec 67 INFO: UPX is not available. 69 INFO: Extending PYTHONPATH with paths ['/Users/lizhonglin/Desktop/stuflask', '/Users/lizhonglin/Desktop/stuflask'] 69 INFO: checking Analysis 69 INFO: Building Analysis because Analysis-00.toc is non existent 69 INFO: Initializing module dependency graph... 71 INFO: Initializing module graph hooks... 72 INFO: Analyzing base_library.zip ... 3562 INFO: running Analysis Analysis-00.toc 3574 INFO: Caching module hooks... 3579 INFO: Analyzing /Users/lizhonglin/Desktop/stuflask/manage.py 4249 INFO: Processing pre-find module path hook distutils 4249 INFO: distutils: retargeting to non-venv dir '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils' 7924 INFO: Processing pre-safe import module hook six.moves 10606 INFO: Processing pre-find module path hook site 10607 INFO: site: retargeting to fake-dir '/Users/lizhonglin/Desktop/Code/axfenv/lib/python3.6/site-packages/PyInstaller/fake-modules' 14279 INFO: Loading module hooks... 14279 INFO: Loading module hook "hook-_tkinter.py"... 14289 INFO: checking Tree 14289 INFO: Building Tree because Tree-00.toc is non existent 14289 INFO: Building Tree Tree-00.toc 14314 INFO: checking Tree 14314 INFO: Building Tree because Tree-01.toc is non existent 14314 INFO: Building Tree Tree-01.toc 14326 INFO: Loading module hook "hook-distutils.py"... 14328 INFO: Loading module hook "hook-encodings.py"... 14412 INFO: Loading module hook "hook-IPython.py"... 14421 INFO: Excluding import 'matplotlib' 14426 INFO: Removing import of matplotlib from module IPython.core.pylabtools 14428 INFO: Import to be excluded not found: 'PyQt4' 14428 INFO: Import to be excluded not found: 'PyQt5' 14428 INFO: Excluding import 'tkinter' 14432 INFO: Removing import of tkinter from module IPython.lib.clipboard 14434 INFO: Import to be excluded not found: 'gtk' 14434 INFO: Import to be excluded not found: 'PySide' 14434 INFO: Loading module hook "hook-jedi.py"... 14436 INFO: Loading module hook "hook-jinja2.py"... 14463 INFO: Loading module hook "hook-pkg_resources.py"... 15022 INFO: Processing pre-safe import module hook win32com 15023 INFO: Loading module hook "hook-pydoc.py"... 15024 INFO: Loading module hook "hook-pygments.py"... 17298 INFO: Loading module hook "hook-sqlalchemy.py"... 17485 INFO: Found 6 sqlalchemy hidden imports 17486 WARNING: Hidden import "MySQLdb" not found! 17517 WARNING: Hidden import "sqlalchemy.orm.state", "sqlalchemy.orm.strategies" not found! 17518 WARNING: Hidden import "sqlalchemy.sql.functions.func" not found! 17523 INFO: Excluding import 'sqlalchemy.testing' 17527 INFO: Removing import of sqlalchemy.testing.util from module sqlalchemy.orm.util 17528 INFO: Removing import of sqlalchemy.testing from module sqlalchemy.testing 17528 INFO: Removing import of sqlalchemy.testing.engines from module sqlalchemy.testing 17528 INFO: Removing import of sqlalchemy.testing.exclusions from module sqlalchemy.testing 17528 INFO: Removing import of sqlalchemy.testing.util from module sqlalchemy.testing 17528 INFO: Removing import of sqlalchemy.testing.warnings from module sqlalchemy.testing 17528 INFO: Removing import of sqlalchemy.testing.config from module sqlalchemy.testing 17528 INFO: Removing import of sqlalchemy.testing.mock from module sqlalchemy.testing 17528 INFO: Removing import of sqlalchemy.testing.assertions from module sqlalchemy.testing 17529 INFO: Removing import of sqlalchemy.testing.assertsql from module sqlalchemy.testing 17529 INFO: Removing import of sqlalchemy.testing from module sqlalchemy.testing.warnings 17529 INFO: Removing import of sqlalchemy.testing.assertions from module sqlalchemy.testing.warnings 17529 INFO: Removing import of sqlalchemy.testing from module sqlalchemy.testing.assertions 17529 INFO: Removing import of sqlalchemy.testing.exclusions from module sqlalchemy.testing.assertions 17529 INFO: Removing import of sqlalchemy.testing.util from module sqlalchemy.testing.assertions 17529 INFO: Removing import of sqlalchemy.testing.mock from module sqlalchemy.testing.assertions 17529 INFO: Removing import of sqlalchemy.testing.config from module sqlalchemy.testing.assertions 17529 INFO: Removing import of sqlalchemy.testing.assertsql from module sqlalchemy.testing.assertions 17529 INFO: Removing import of sqlalchemy.testing from module sqlalchemy.testing.util 17529 INFO: Removing import of sqlalchemy.testing.engines from module sqlalchemy.testing.util 17529 INFO: Removing import of sqlalchemy.testing.config from module sqlalchemy.testing.util 17529 INFO: Removing import of sqlalchemy.testing from module sqlalchemy.testing.config 17530 INFO: Removing import of sqlalchemy.testing from module sqlalchemy.testing.engines 17530 INFO: Removing import of sqlalchemy.testing.assertions from module sqlalchemy.testing.engines 17530 INFO: Removing import of sqlalchemy.testing.util from module sqlalchemy.testing.engines 17530 INFO: Removing import of sqlalchemy.testing.config from module sqlalchemy.testing.engines 17532 INFO: Removing import of sqlalchemy.testing from module sqlalchemy.testing.exclusions 17532 INFO: Removing import of sqlalchemy.testing.config from module sqlalchemy.testing.exclusions 17532 INFO: Removing import of sqlalchemy.testing from module sqlalchemy.testing.assertsql 17532 INFO: Removing import of sqlalchemy.testing from module sqlalchemy.testing.mock 17533 INFO: Loading module hook "hook-sqlite3.py"... 17622 INFO: Loading module hook "hook-sysconfig.py"... 17632 INFO: Loading module hook "hook-xml.dom.domreg.py"... 17632 INFO: Loading module hook "hook-xml.py"... 17633 INFO: Loading module hook "hook-PIL.Image.py"... 17971 INFO: Loading module hook "hook-PIL.py"... 17977 INFO: Excluding import 'PyQt4' 17980 INFO: Removing import of PyQt4 from module PIL.ImageQt 17981 INFO: Excluding import 'PyQt5' 17984 INFO: Removing import of PyQt5 from module PIL.ImageQt 17986 INFO: Excluding import 'tkinter' 17991 INFO: Removing import of tkinter from module PIL.ImageTk 17991 INFO: Import to be excluded not found: 'FixTk' 17991 INFO: Excluding import 'PySide' 17994 INFO: Removing import of PySide from module PIL.ImageQt 17995 INFO: Loading module hook "hook-PIL.SpiderImagePlugin.py"... 17997 INFO: Excluding import 'tkinter' 17999 INFO: Import to be excluded not found: 'FixTk' 18058 INFO: Looking for ctypes DLLs 18108 WARNING: library ktmw32.dll required via ctypes not found 18114 INFO: Analyzing run-time hooks ... 18126 INFO: Including run-time hook 'pyi_rth_pkgres.py' 18127 INFO: Including run-time hook 'pyi_rth_multiprocessing.py' 18131 INFO: Including run-time hook 'pyi_rth_traitlets.py' 18159 INFO: Looking for dynamic libraries 18707 INFO: Looking for eggs 18707 INFO: Using Python library /Users/lizhonglin/Desktop/Code/axfenv/bin/../.Python 18720 INFO: Warnings written to /Users/lizhonglin/Desktop/stuflask/build/manage/warn-manage.txt 18851 INFO: Graph cross-reference written to /Users/lizhonglin/Desktop/stuflask/build/manage/xref-manage.html 18914 INFO: checking PYZ 18914 INFO: Building PYZ because PYZ-00.toc is non existent 18914 INFO: Building PYZ (ZlibArchive) /Users/lizhonglin/Desktop/stuflask/build/manage/PYZ-00.pyz 20558 INFO: Building PYZ (ZlibArchive) /Users/lizhonglin/Desktop/stuflask/build/manage/PYZ-00.pyz completed successfully. 20600 INFO: checking PKG 20601 INFO: Building PKG because PKG-00.toc is non existent 20601 INFO: Building PKG (CArchive) PKG-00.pkg 27758 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully. 27763 INFO: Bootloader /Users/lizhonglin/Desktop/Code/axfenv/lib/python3.6/site-packages/PyInstaller/bootloader/Darwin-64bit/run 27763 INFO: checking EXE 27763 INFO: Building EXE because EXE-00.toc is non existent 27763 INFO: Building EXE from EXE-00.toc 27763 INFO: Appending archive to EXE /Users/lizhonglin/Desktop/stuflask/dist/manage 27794 INFO: Fixing EXE for code signing /Users/lizhonglin/Desktop/stuflask/dist/manage 27797 INFO: Building EXE from EXE-00.toc completed successfully. (axfenv) lizhonglindeMacBook-Pro:stuflask lizhonglin$ |
打包完成后项目的文件夹下面就多了两个文件夹和一个文件
如果想要给打包后的exe文件添加一个图标在打包的时候需要输入如下命令
1 |
pyinstaller -F -i b.ico 打包的文件.py |
在dist目录就有打包好的manage.exe可执行程序了。
在windows中双击就可以运行后端程序了。启动后的效果
原创出品,喜欢可以收藏转载哦!!!
作者:lizhonglin
github: https://github.com/Leezhonglin/