ubuntu&windows上打包python程序

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目录都打包

参考文章

Ubuntu安装conda

将python程序变成可执行程序

 

posted @   kongbursi  阅读(652)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
历史上的今天:
2020-04-11 Link/Cut Tree CodeForces - 614A 暴力+爆 long long 处理
2020-04-11 Is It A Tree? POJ - 1308
2020-04-11 Ants POJ - 1852
2020-04-11 Splits CodeForces - 964A
2020-04-11 Splits CodeForces - 964A
2020-04-11 Common Divisors CodeForces - 1203C
2019-04-11 C - BLG POJ - 1417 种类并查集加dp(背包)
点击右上角即可分享
微信分享提示