使用pyinstaller打包python文件
使用pyinstaller打包python文件
1. 下载pyinstaller
根据自己python版本,下载合适pyinstaller版本,我的python版本为3.6,查询pyinstaller合适版本为4.0及以下。
注意:pyinstaller安装位置与项目尽量为一个环境。
pip install pyinstaller==3.7
2. 打包
我使用的是anaconda虚拟环境,右键Anaconda Prompt,使用管理员权限打开。
(base) C:\WINDOWS\system32> cd C:\tmp
(base) C:\tmp> pyinstaller --onefile spider.py
3. 过程报错
若打包过程报错:'utf-8' codec can't decode byte 0xce in position 119: invalid continuation byte
- 在所有python文件头部加上:
# -*- coding: utf-8 -*-
- 在Anaconda Prompt命令行窗口输入:
chcp 65001
- 修改D:\software\Anaconda3\Lib\site-packages\PyInstaller\compat.py文件代码
# 将
out = out.decode(encoding)
# 改为
out = out.decode(encoding, errors='ignore')
God will send the rain when you are ready.You need to prepare your field to receive it.