文章目录
- 一、安装Python
- 二、安装pip
- 三、通过pip安装pyinstaller
- 四、使用pyinstaller打包python为二进制程序
- 参考
一、安装Python
我这里直接下载的是Python的可执行程序包,打开即用的版本,
也可以按照以下的教程安装python工具到windows上面
(1)去官网下载:Download Python | Python.org
(2)找到合适 版本进行下载
(3)直接执行安装就好了,注意安装结束后要设置环境变量,或者安装时有选型可以勾选上不用设置环境变量也可以
二、安装pip
参考官方教程给出的几个方法进行安装
这里采用脚本的方式安装
(1)安全下载 get-pip.py
(2)运行 python get-pip.py . 2 这将安装或升级 pip。此外,如果 Setuptools 和 wheel 尚未安装,它也会安装。
D:\Runtime\pip>D:\Runtime\python-3.8.1rc1-embed-amd64\python.exe get-pip.py
三、通过pip安装pyinstaller
(1)配置pip安装源
在运行窗口中输入%APPDATA%后回车,创建名为pip的目录,在pip目录中创建pip.ini配置文件
pip.ini配置如下
[global]
index-url=https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
(2)pip安装pyinstaller
C:\Users\script.wang>pip install pyinstaller
(3)查看安装pyinstaller的安装位置
C:\Users\script.wang>pip show pyinstaller
Name: pyinstaller
Version: 6.10.0
Summary: PyInstaller bundles a Python application and all its dependencies into a single package.
Home-page: https://www.pyinstaller.org/
Author: Hartmut Goebel, Giovanni Bajo, David Vierra, David Cortesi, Martin Zibricky
Author-email: None
License: GPLv2-or-later with a special exception which allows to use PyInstaller to build and distribute non-free programs (including commercial ones)
Location: c:\users\script.wang\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Requires: packaging, altgraph, pywin32-ctypes, setuptools, pyinstaller-hooks-contrib, pefile, importlib-metadata
Required-by:
C:\Users\script.wang>
可以看到pyinstaller安装到目录:c:\users\script.wang\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages下面了。其执行程序在C:\Users\script.wang\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\Scripts\目录下面(需要自己找找看),使用pyinstaller全路径即可执行
C:\Users\script.wang\Desktop>C:\Users\script.wang\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\Scripts\pyinstaller.exe -h
usage: pyinstaller [-h] [-v] [-D] [-F] [--specpath DIR] [-n NAME] [--contents-directory CONTENTS_DIRECTORY]
[--add-data SOURCE:DEST] [--add-binary SOURCE: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]
[--splash IMAGE_FILE] [-d {all,imports,bootloader,noarchive}] [--optimize LEVEL] [--python-option PYTHON_OPTION]
[-s] [--noupx] [--upx-exclude FILE] [-c] [-w]
[--hide-console {hide-late,hide-early,minimize-late,minimize-early}]
[-i <FILE.ico or FILE.exe,ID or FILE.icns or Image or "NONE">] [--disable-windowed-traceback]
[--version-file FILE] [--manifest <FILE or XML>] [-m <FILE or XML>] [-r RESOURCE] [--uac-admin] [--uac-uiaccess]
[--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] [--clean]
[--log-level LEVEL]
scriptname [scriptname ...]
四、使用pyinstaller打包python为二进制程序
C:\Users\script.wang\Desktop>C:\Users\script.wang\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\Scripts\pyinstaller.exe -F xx.py --nowindowed
参考
- python安装、配置以及pyinstaller的安装、使用
- Windows 10使用PyInstaller将Python代码打包成exe程序
- 官方手册
- windows下安装pyinstaller以及依赖的软件安装