Python打包为exe详细教程
作者:鱼丸丶粗面 时间:2023-08-23 03:00:21
一、安装 → pyinstaller
1.1 方式1:cmd
1. 调出运行窗口:win + r, 并输入 cmd
2. 切换到 pip.exe 目录(Scripts,参考如下:)
cd C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\Scripts
# D: # 若是其它盘,如 D
# cd D:\xx
3. 执行命令 pip install pyinstaller
1. 切换到 pip.exe 的目录(找到你本地 pip 目录路径)
import os
# lib 为 path 库的目录,Scripts 为 pip.exe 的目录
lib = os.path.dirname(os.path.__file__)
pip = os.path.join(os.path.dirname(lib), 'Scripts')
# print(lib)
print(pip)
查询结果:说明(C:\xx 是单独安装、环境变量中配置的,D:\xx 是 Pycharm 自带的)
2. 安装 pyinstaller
1.2 方式2:Pycharm
1. 调出执行命令窗口:快捷键 Alt + F12
2. 切换到 Pycharm Scripts 目录
(1) cd D:\xx\venv\Script # xx: 自己本地路径
(2) pip install pyinstaller
最简单:选中 pyinstaller,Alt + Enter,直接选择安装即可
(右下角)提示安装成功,即可。
二、打包 → pyinstaller -F *.py
1. 命令: pyinstaller -F *.py(星号为py文件的全路径,如下图)
(1) F : '大写'
(2) * : '需要打包的 .py 文件的绝对路径'
2. 说明
(1) 绝对路径中,不能带有 '空格'
2.1 执行命令
2.2 文件目录
三、可能存在问题
3.1 不是内部或外部命令
错误截图:
错误原因:没有配置 "环境变量"
解决方案:Python 环境变量配置详解
来源:https://blog.csdn.net/qq_34745941/article/details/116861359
标签:Python,打包exe
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python爬虫之Selenium实现窗口截图
2022-09-19 20:09:23
![](https://img.aspxhome.com/file/2023/4/121064_0s.jpg)
浅谈javascript 迭代方法
2024-06-07 15:50:55
MySQL系列教程小白数据库基础
2024-01-13 08:23:19
![](https://img.aspxhome.com/file/2023/1/107431_0s.png)
MySql安装启动两种方法教程详解
2024-01-16 11:32:53
![](https://img.aspxhome.com/file/2023/8/128418_0s.png)
Oracle PL/SQL语言入门基础
2010-07-20 13:28:00
两个百度WEB面试题 怎么做?
2010-09-03 18:40:00
Python常用模块sys,os,time,random功能与用法实例分析
2023-07-16 12:50:57
![](https://img.aspxhome.com/file/2023/2/60982_0s.png)
fetch 使用及如何接收JS传值
2024-04-29 13:11:21
javascript代码实现简易计算器
2024-04-16 08:57:46
![](https://img.aspxhome.com/file/2023/5/136735_0s.jpg)
Python使用requests及BeautifulSoup构建爬虫实例代码
2021-08-13 11:33:13
![](https://img.aspxhome.com/file/2023/3/121043_0s.jpg)
使用uni-app开发微信小程序的实现
2024-05-13 09:10:42
![](https://img.aspxhome.com/file/2023/9/126499_0s.png)
Python中用字符串调用函数或方法示例代码
2023-03-05 15:37:59
python淘宝准点秒杀抢单的实现示例
2021-08-20 17:50:23
![](https://img.aspxhome.com/file/2023/6/128606_0s.png)
php字符串过滤strip_tags()函数用法实例分析
2023-09-04 14:05:00
Python字符转换
2021-08-23 04:47:13
浅谈在django中使用filter()(即对QuerySet操作)时踩的坑
2022-05-03 10:24:49
![](https://img.aspxhome.com/file/2023/6/101736_0s.jpg)
python分割和拼接字符串
2023-05-12 05:57:03
Python 标准库 fileinput与文件迭代器
2023-10-31 22:36:50
详解Javascript 装载和执行
2024-04-18 09:41:02
如何彻底解决python NameError:name '__file__' is not defined
2023-01-29 03:57:12
![](https://img.aspxhome.com/file/2023/7/124187_0s.png)