python中pyinstaller库的使用

使用pyinstaller打包python程序为exe文件

安装pyinstaller库

1
pip install pyinstaller

拿一个我以前写过的简单项目来测试打包

以前的项目结构如下

2

安装完成之后看到如下界面

1

在虚拟环境下面运行如下命令

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

3

在dist目录就有打包好的manage.exe可执行程序了。

在windows中双击就可以运行后端程序了。启动后的效果

4

原创出品,喜欢可以收藏转载哦!!!

作者:lizhonglin

github: https://github.com/Leezhonglin/

blog: https://leezhonglin.github.io/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 要安装Pythonpyinstaller,可以按照以下步骤进行: 1. 打开命令行窗口(Windows用户可以按下Win+R键,输入cmd并按下回车键)。 2. 输入以下命令来安装pyinstaller: pip install pyinstaller 3. 等待安装完成即可。 注意:在安装pyinstaller之前,需要确保已经安装了Python和pip工具。如果没有安装,可以先安装Python,然后使用Python自带的pip工具来安装pyinstaller。 ### 回答2: Python是一种开源的高级编程语言,被广泛应用于Web开发、科学计算、人工智能等领域。PyInstaller是一个第三方,可以将Python程序打包成一个独立的可执行文件,方便用户在不安装Python解释器的情况下直接运行程序。 以下是Python安装PyInstaller的步骤: 1. 安装Python 首先需要安装Python解释器,可以从官网下载适合自己系统版本的Python安装文件,双击运行即可。 2. 安装pip pip是Python的包管理器,用来安装和管理Python。可以在终端(或命令提示符)输入以下命令安装pip: ``` python -m ensurepip ``` 如果系统提示没有权限,可以使用管理员身份运行该命令。 3. 安装PyInstaller 在终端输入以下命令安装PyInstaller: ``` pip install pyinstaller ``` 此时pip会自动下载和安装PyInstaller及其依赖项。 4. 打包Python程序 打开终端,切换到Python程序所在的目录,输入以下命令: ``` pyinstaller -F myprogram.py ``` 其myprogram.py是Python程序的名称。-F参数指定将Python程序打包成单独的一个可执行文件。 打包完成后,可以在dist目录下找到生成的可执行文件。 总结: 安装PyInstaller的过程比较简单,只需要安装Python和pip后,可以通过pip安装PyInstallerPyInstaller可以方便地将Python程序打包成可执行文件,方便用户在不安装Python解释器的情况下直接运行程序。需要注意的是,打包Python程序时要指定打包方式及程序名称等参数。 ### 回答3: Python是一种流行的编程语言,被广泛用于各种任务,包括Web开发、自动化、数据分析等等。在Python编程,有很多非常方便的和工具,其就包括PyInstaller,该可以将Python程序转换成本地可执行文件。下面是Python安装PyInstaller的步骤。 第一步,打开终端或命令提示符。对于Windows用户,可以按下Win+R键打开运行窗口,输入cmd,按下回车键。 第二步,安装PyInstaller。在终端或命令提示符,输入以下命令: ``` pip install pyinstaller ``` 这个命令会从Python的包管理系统以及下载并安装PyInstaller。如果你在安装过程遇到问题,请检查你的网络连接,确保PyPI可以访问,或者尝试使用以下命令: ``` pip install --index-url=http://pypi.python.org/simple/ pyinstaller ``` 此命令将PyPI的源更改为http://pypi.python.org/simple/,这通常可以帮助解决访问问题。 第三步,测试PyInstaller是否安装成功。在终端或命令提示符,输入以下命令: ``` pyinstaller --version ``` 如果成功安装了PyInstaller,这个命令会返回PyInstaller版本号。如果没有,则说明安装遇到了问题。 现在,你已经成功安装了PyInstaller,可以将Python程序转换为本地可执行文件。有了这个工具,你可以更方便地分享你的Python应用程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kujirashark

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值