ubuntu&windows上打包python程序
2023-09-27 14:26:02 时间
Windows
安装pyinstaller
pip install pyinstaller
测试是否安装成功
pyinstaller -v
打包
pyinstaller --onefile your_program.py #或者 pyinstaller your_program.py
然后会把当前目录下生成一个dist目录和一个build目录
可执行文件就在dist里面,给其他人用的时候需要把整个dist目录都打包,而不能只给一个exe可执行程序
问题
安装pyinstaller之后使用pyinstaller -v输出 “没有pyinstaller这个程序”
那我们可以找到pyinstaller.exe的位置,把它添加到环境变量 或者 直接在pyinstaller.exe的位置打开cmd。
#找到pyinstaller的位置
D:\Downloads\TicketBot>pip show pyinstaller Name: pyinstaller Version: 5.9.0 Summary: PyInstaller bundles a Python application and all its dependencies into a single package. Home-page: https://www.pyinstaller.org/ Author: Hartmut Goebel, Giovanni Bajo, David Vierra, David Cortesi, Martin Zibricky Author-email: License: GPLv2-or-later with a special exception which allows to use PyInstaller to build and distribute non-free programs (including commercial ones) Location: c:\users\us\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages Requires: altgraph, pefile, pyinstaller-hooks-contrib, pywin32-ctypes, setuptools Required-by:
可执行文件在:
c:\users\us\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\Scripts
Ubuntu
安装conda
1. 下载anaconda安装包:清华镜像
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2021.11-Linux-x86_64.sh
可直接从清华镜像网站上下载anaconda安装包, 视情况选择自己的版本,我选择的是2021.11版本。
2.安装包下载完成之后键入
bash Anaconda3-2021.11-Linux-x86_64.sh
期间有ENTER的地方可以直接回车,遇到MORE信息,可以摁Q键跳过,遇到需要输入yes|no的地方输入yes即可。
3.安装完成后在终端修改环境变量,键入
gedit ~/.bashrc
在弹出的文本框最下面键入
export PATH="/home/sxm/anaconda3/bin:$PATH"
sxm是我本机,这里需要根据自己的本机做修改,然后点SAVE保存修改。
4.生效
source ~/.bashrc
打包可执行程序
1.新建一个conda环境,名为pyinstall。这样做也是为了方便与其他环境隔离
conda create -n pyinstall python=3.8
2.激活环境
source activate pyinstall
3.安装pyinstaller包
python -m pip install pyinstaller
4.打包
pyinstaller --onefile --console demo.py #或者 pyinstaller --console demo.py
可执行文件就在dist里面,给其他人用的时候需要把整个dist目录都打包
参考文章
相关文章
- Python数据清洗 & 预处理入门完整指南【建议收藏】
- Python OpenCV图像处理 理论 & 代码
- 第25天:Python datetime&time
- 精品基于Python的高校学生职业推荐平台兼职招聘求职
- Python 测试框架之 Unittest & Pytest
- 【Python】添加注册表信息脚本
- 【Raspberry Pi】定时运行python程序读温湿度传感器数据&发邮件
- 【Python & mxnet & gluon】基于 gluon 的自定义线性回归(创建数据集 || 数据读取 || 初始化模型参数 || 定义模型 损失函数 || 优化 || 训练)
- python 详解re模块
- Python 异常处理
- 【Python & Other】一网打尽 Python复制文本&文件到剪切板
- PyQt(Python+Qt)学习随笔:formLayout的layoutLabelAlignment 属性
- python编程(类变量和实例变量)
- 入门Python必备100道练习题
- Python 的windows平台非官方集成包下载站
- Python 进阶_迭代器 & 列表解析
- python的单元测试
- PTA 题解:jmu-Java&Python-统计文字中的单词数量并按出现次数排序
- python - 计算百分比保留多位小数
- Python基本语法_函数属性 & 参数类型 & 偏函数的应用
- Ubuntu/Linux 下切换 python 版本