ubuntu20.04

您所在的位置:网站首页 python文件打包成可执行文件 ubuntu20.04

ubuntu20.04

2023-09-06 08:12| 来源: 网络整理| 查看: 265

python比较麻烦的一点是环境依赖很重,如果直接用脚本在不同环境使用,必定会导致结果不一致的情况。

所以,将python打包成二进制进行发布,就避免了这个问题。

pyinstaller用于将Python文件和依赖包打包成为Linux可执行程序,方便在不同机器调用。 跨平台,支持win,nux,mac。

打包环境 ubuntu20.04 python3

1.安装步骤 1>安装pip/pip3 sudo apt-get install python3-pip2>更换pip3下载源 sudo su mkdir -p /root/.pip cd /root/.pip vim pip.conf

3> 写入pip.conf

[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple [install] trusted-host=pypi.tuna.tsinghua.edu.cn

4> 安装pyinstaller pip3 install pyinstaller

2.使用方式

常用如下参数:

What to generate: -D, --onedir Create a one-folder bundle containing an executable (default) -F, --onefile Create a one-file bundled executable. --specpath DIR Folder to store the generated spec file (default: current directory) -n NAME, --name NAME Name to assign to the bundled app and spec file (default: first script's basename)

一般使用方式 回到要打包的文件所在目录

pyinstaller -F 要打包的.py文件

执行完毕后,源文件所在目录将生成 dist 和 build 两个文件夹。

build 目录是 pyinstaller 存储临时文件的目录,可以安全删除dist 目录存储二进制相关内容。目录中其他文件是可执行文件 dpython.exe 的动态链接库。

生成目录如下: 打包二进制目录如图所示

注意: 再次生成时,需要删除上次生成的二进制文件注意打包机器和二进制使用的系统保持一致python打包也可以使用docker,后续有空再整理一波

更多使用方式:pyinstaller -h 在这里插入图片描述



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3