在工作中,我们可以使用Python编写一些小工具来提高工作效率,对于常用的工具的话可以将其打包成一个可执行文件,这样就比较方便使用了,下面演示一下我是如何打包我的程序的。
1、安装环境
首先我们要安装pip,命令如下:
sudo apt install python3-pip

安装pip
然后我们通过pip安装pyinstaller,命令如下:
sudo pip3 install pyinstaller

到这里,打包环境就配置完成了,下面开始进行打包
2、打包程序
在打包之前,我们先运行看看是否正常:

运行结果
此时,运行是没问题的,然后我们开始打包:
pyinstaller -F http.py

执行结果
然后我们进入打包好的执行文件存放目录
cd dist/
ls
尝试执行:
./http

执行打包好的可执行文件
此时执行是没问题的,接着我们把其他内容都删除(把执行文件移动到新的目录也行)之后再执行:

此时运行仍然没有问题,那么本篇文章介绍就到这里了
原文地址:https://www.toutiao.com/a6917558021296062989/