安装pyinstaller和使用操作
第一种方法:
-
说明:
安装pyinstaller:
-
桌面下,按win+r 弹出搜索框
-
输入cmd
-
进入命令提示符
-
输入pip install pyinstaller
-
等待安装
-
完成会有提示 Successfully installed altgraph-0.17 future-0.18.2 pefile-2019.4.18 pyinstaller-4.0
-
以下是记录:
Microsoft Windows [版本 10.0.18363.1198]
(c) 2019 Microsoft Corporation。保留所有权利。
C:\Users\Lenovo>pip install pyinstaller
Collecting pyinstaller
Downloading https://files.pythonhosted.org/packages/82/96/21ba3619647bac2b34b4996b2dbbea8e74a703767ce24192899d9153c058/pyinstaller-4.0.tar.gz (3.5MB)
100% |████████████████████████████████| 3.5MB 126kB/s
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
Collecting pyinstaller-hooks-contrib>=2020.6 (from pyinstaller)
Downloading https://files.pythonhosted.org/packages/2a/e6/4a47a7d41266cbca531bed3031c6412f9601ba2a2319e6d8c43f6917c51d/pyinstaller_hooks_contrib-2020.10-py2.py3-none-any.whl (166kB)
100% |████████████████████████████████| 174kB 95kB/s
Collecting altgraph (from pyinstaller)
Downloading https://files.pythonhosted.org/packages/ee/3d/bfca21174b162f6ce674953f1b7a640c1498357fa6184776029557c25399/altgraph-0.17-py2.py3-none-any.whl
Collecting pywin32-ctypes>=0.2.0; sys_platform == "win32" (from pyinstaller)
Downloading https://files.pythonhosted.org/packages/9e/4b/3ab2720f1fa4b4bc924ef1932b842edf10007e4547ea8157b0b9fc78599a/pywin32_ctypes-0.2.0-py2.py3-none-any.whl
Requirement already satisfied: setuptools in d:\software\python\lib\site-packages (from pyinstaller) (40.8.0)
Collecting pefile>=2017.8.1; sys_platform == "win32" (from pyinstaller)
Downloading https://files.pythonhosted.org/packages/36/58/acf7f35859d541985f0a6ea3c34baaefbfaee23642cf11e85fe36453ae77/pefile-2019.4.18.tar.gz (62kB)
100% |████████████████████████████████| 71kB 33kB/s
Collecting future (from pefile>=2017.8.1; sys_platform == "win32"->pyinstaller)
Downloading https://files.pythonhosted.org/packages/45/0b/38b06fd9b92dc2b68d58b75f900e97884c45bedd2ff83203d933cf5851c9/future-0.18.2.tar.gz (829kB)
100% |████████████████████████████████| 829kB 114kB/s
Building wheels for collected packages: pyinstaller
Building wheel for pyinstaller (PEP 517) ... done
Stored in directory: C:\Users\Lenovo\AppData\Local\pip\Cache\wheels\cb\91\a9\1e2b69cf9e01f0f6a89c2c6166324319ca6273d26604b200b6
Successfully built pyinstaller
Installing collected packages: pyinstaller-hooks-contrib, altgraph, pywin32-ctypes, future, pefile, pyinstaller
Running setup.py install for future ... done
Running setup.py install for pefile ... done
Successfully installed altgraph-0.17 future-0.18.2 pefile-2019.4.18 pyinstaller-4.0 pyinstaller-hooks-contrib-2020.10 pywin32-ctypes-0.2.0
You are using pip version 19.0.3, however version 20.3b1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
- 然后可以输入pyinstaller试一下,会有显示的,也能说明安装成功。
C:\Users\Lenovo>pyinstaller
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]
[--additional-hooks-dir HOOKSPATH]
[--runtime-hook RUNTIME_HOOKS] [--exclude-module EXCLUDES]
[--key KEY] [-d {all,imports,bootloader,noarchive}] [-s]
[--noupx] [--upx-exclude FILE] [-c] [-w]
[-i <FILE.ico or FILE.exe,ID or FILE.icns>]
[--version-file FILE] [-m <FILE or XML>] [-r RESOURCE]
[--uac-admin] [--uac-uiaccess] [--win-private-assemblies]
[--win-no-prefer-redirects]
[--osx-bundle-identifier BUNDLE_IDENTIFIER]
[--runtime-tmpdir PATH] [--bootloader-ignore-signals]
[--distpath DIR] [--workpath WORKPATH] [-y]
[--upx-dir UPX_DIR] [-a] [--clean] [--log-level LEVEL]
scriptname [scriptname ...]
pyinstaller: error: the following arguments are required: scriptname
- 将py文件变为可执行文件:
- j继续在命令提示符中输入pyinstaller -F e:\脚本.py
- F 后面是文件地址
- Appending archive to EXE C:\Users\Lenovo\dist\脚本.exe,这个是可执行文件的存放位置
C:\Users\Lenovo>pyinstaller -F e:\脚本.py
45 INFO: PyInstaller: 4.0
45 INFO: Python: 3.7.4
46 INFO: Platform: Windows-10-10.0.18362-SP0
47 INFO: wrote C:\Users\Lenovo\脚本.spec
51 INFO: UPX is not available.
54 INFO: Extending PYTHONPATH with paths
['e:\\', 'C:\\Users\\Lenovo']
59 INFO: checking Analysis
59 INFO: Building Analysis because Analysis-00.toc is non existent
60 INFO: Initializing module dependency graph...
63 INFO: Caching module graph hooks...
72 INFO: Analyzing base_library.zip ...
3945 INFO: Caching module dependency graph...
4034 INFO: running Analysis Analysis-00.toc
4068 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by d:\software\python\python.exe
4154 INFO: Analyzing e:\脚本.py
4251 INFO: Processing pre-safe import module hook urllib3.packages.six.moves from 'd:\\software\\python\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-urllib3.packages.six.moves.py'.
5461 INFO: Processing module hooks...
5461 INFO: Loading module hook 'hook-certifi.py' from 'd:\\software\\python\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
5468 INFO: Loading module hook 'hook-encodings.py' from 'd:\\software\\python\\lib\\site-packages\\PyInstaller\\hooks'...
5616 INFO: Loading module hook 'hook-xml.py' from 'd:\\software\\python\\lib\\site-packages\\PyInstaller\\hooks'...
5681 INFO: Looking for ctypes DLLs
5681 INFO: Analyzing run-time hooks ...
5685 INFO: Including run-time hook 'd:\\software\\python\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\rthooks\\pyi_rth_certifi.py'
5689 INFO: Looking for dynamic libraries
5900 INFO: Looking for eggs
5900 INFO: Using Python library d:\software\python\python37.dll
5901 INFO: Found binding redirects:
[]
5905 INFO: Warnings written to C:\Users\Lenovo\build\上网登录脚本\warn-上网登录脚本.txt
5956 INFO: Graph cross-reference written to C:\Users\Lenovo\build\上网登录脚本\xref-上网登录脚本.html
5977 INFO: checking PYZ
5977 INFO: Building PYZ because PYZ-00.toc is non existent
5979 INFO: Building PYZ (ZlibArchive) C:\Users\Lenovo\build\上网登录脚本\PYZ-00.pyz
6442 INFO: Building PYZ (ZlibArchive) C:\Users\Lenovo\build\上网登录脚本\PYZ-00.pyz completed successfully.
6450 INFO: checking PKG
6450 INFO: Building PKG because PKG-00.toc is non existent
6451 INFO: Building PKG (CArchive) PKG-00.pkg
7800 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
7803 INFO: Bootloader d:\software\python\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
7803 INFO: checking EXE
7803 INFO: Building EXE because EXE-00.toc is non existent
7805 INFO: Building EXE from EXE-00.toc
7807 INFO: Appending archive to EXE C:\Users\Lenovo\dist\上网登录脚本.exe
7813 INFO: Building EXE from EXE-00.toc completed successfully.
第二种方法
- 在pycharm集成开发工具中安装pyinstaller
在pycharm中使用pyinstaller
第一种
在终端控制台进行操作 (操作和在命令提示符中的相似)
在pycharm的终端控制台操作
在里面弄
-
它保存路径与在命令提示符中的不一样
-
12186 INFO: Appending archive to EXE E:\保存python文件\dist\网页认证.exe
-
在这里e盘
-
而cmd的在c盘
pyinstaller一般安装在python的安装路径的文件夹中Scripts中
例如:D:\software\python\Scripts\pyinstaller.exe
第二种
在pycharm中配置工具先配置好,方便使用
添加Tool需要配置这三个位置
D:\software\python\Scripts\pyinstaller.exe
-F $FileNameWithoutExtension$.py
$ProjectFileDir$
三个配置参数
然后在这里就可以直接使用
这样操作比上面的相对简单方便。
使用pyinstaller将py文件转化为windows操作系统可执行的文件exe
好处是可以在不安装python解释器中的电脑端使用
缺点是没有和py代码一样可以直接修改,调试。