python打包exe,各种bug处理,以及解决方案

我们在用python打包的时候 常用的是用pipenv来打包,当然还有其他的一些打包软件,我这里以pipenv来介绍:

pipenv 是创造一个虚拟的干净环境,去掉不必要的包,使得小程序的体积控制在1-10M左右,当然如果程序很复杂,也可能会超过不少具体看自己程序依赖包的大小。

下面我们就开始介绍一下用anconda集成环境为基础,来用pipenv来打包

1.如果我们安装了各种版本的anconda在配置环境变量以使用pipenv要删除本地的虚拟环境,避免上一个版本使用遗留影响到目前版本的打包:

python打包exe,各种bug处理,以及解决方案

在C:UsersAdministrator.virtualenvs中删除.virtualenvs文件,这是一个虚拟的本地环境也是一个临时环境,可以随时删除没有任何影响

python打包exe,各种bug处理,以及解决方案

桌面上新建文件,把文件进行打包,这里我习惯用Powershell窗口打包

python打包exe,各种bug处理,以及解决方案

进入之前设置anconda国内镜像:

我这里选择阿里巴巴的镜像地址:随意一个cmd窗口执行:

pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/

或者在进入前后都执行一遍,再检查配置文件是否是有镜像库的地址,是否执行成功

python打包exe,各种bug处理,以及解决方案

python打包exe,各种bug处理,以及解决方案

进入pipenv 环境 pipenv shell

python打包exe,各种bug处理,以及解决方案

清空环境 pipenv –rm

python打包exe,各种bug处理,以及解决方案

清空文件锁环境

python打包exe,各种bug处理,以及解决方案

添加依赖包环境,我这里代码看着许多 实则只有一个openpyxl 知识多加了一个 pyinstaller 用于打包

python打包exe,各种bug处理,以及解决方案

配置文件:

[[source]]

url = “https://mirrors.aliyun.com/pypi/simple/”

verify_ssl = true

name = “pypi”

[packages]

openpyxl = “*”

pyinstaller = “*”

[dev-packages]

[requires]

python_version = “3.12”

python打包exe,各种bug处理,以及解决方案

这里 切换配置文件为国内镜像地址后,再进行安装其他的包

python打包exe,各种bug处理,以及解决方案

python打包exe,各种bug处理,以及解决方案

这样打包的时候下载数据会比较快

安装依赖包

pipenv install pyinstaller 这里是打包必备,否则哪怕你在虚拟机中打包,如果没有安装pyinstaller 它会用外包的pyinstaller 会把你的包变得几百M那么大。这是必须的,不行你可以试试。

python打包exe,各种bug处理,以及解决方案

pipenv install openpyxl 这是代码需要依赖的包

python打包exe,各种bug处理,以及解决方案

打包成功后:大约12M

python打包exe,各种bug处理,以及解决方案

双击测试,应用程序就可以执行了

python打包exe,各种bug处理,以及解决方案

永久配置anaconda的镜像地址

cmd中输入命令:

conda config --add channels https://mirrors.aliyun.com/anaconda/pkgs/free/
2conda config --add channels https://mirrors.aliyun.com/anaconda/pkgs/main/
3conda config --set show_channel_urls yes

查看配置

conda config --show

出现以下说明配置成功

python打包exe,各种bug处理,以及解决方案

© 版权声明
THE END
如果内容对您有所帮助,就支持一下吧!
点赞0 分享
健康咨询小贴士的头像 - 鹿快
评论 抢沙发

请登录后发表评论

    暂无评论内容