胡天赐啊 发表于 2020-6-4 17:35:46

能不能把自己编的python包装成可执行文件发送出去

我自己编个一个小程序,想发给朋友看看,能不能把它变成可执行文件发出去,朋友点开就能运行

Twilight6 发表于 2020-6-4 17:36:14

可以的 用 pyinstaller 打包成exe

Twilight6 发表于 2020-6-4 17:41:01

安装 pyinstaller 模块:
python -m pip install pyinstaller -i https://pypi.tuna.tsinghua.edu.cn/simple

打包流程:

将 需要打包的文件放一起   比如 我在 C盘创个py文件夹脚本为 x.py 图表为 z.ico

1. 打开 cmd 窗口 输入将工作目录切换到py文件夹下cd C:\py

2.输入 pyinstaller -F -i z.ico x.py 回车进行打包操作

3.打包完成后在 dist 文件夹下可找到 exe 程序

ps: 若是 gui 界面程序 建议 -F前面加上 -w 可隐藏 cmd 窗口运行

jia159753 发表于 2020-6-4 20:47:37

学习

胡天赐啊 发表于 2020-6-5 10:59:06

Twilight6 发表于 2020-6-4 17:41
安装 pyinstaller 模块:




大佬,为啥我安装了pyinstaller后,打包的时候出现:'pyinstaller' 不是内部或外部命令,也不是可运行的程序
或批处理文件。格式这些都没问题,是不是安装的位置我放错了,我放在C:\Users\86189\AppData\Local\Programs\Python\Python38-32\Scripts
下载的默认地址文件夹scripts里面了,以前安装的模块我都放在这里面

Twilight6 发表于 2020-6-5 11:02:10

胡天赐啊 发表于 2020-6-5 10:59
大佬,为啥我安装了pyinstaller后,打包的时候出现:'pyinstaller' 不是内部或外部命令,也不是可运行的 ...

你没安装成功吗?python -m pip install pyinstaller -i https://pypi.tuna.tsinghua.edu.cn/simple
这个安装过没

胡天赐啊 发表于 2020-6-5 11:17:04

Twilight6 发表于 2020-6-5 11:02
你没安装成功吗?python -m pip install pyinstaller -i https://pypi.tuna.tsinghua.edu.cn/simple
这 ...

应该安装成功了呀,我环境没设置好,以前的东西都是安装在C:\Users\86189\AppData\Local\Programs\Python\Python38-32\Scripts
我这个地址是系统下载python的时候默认的地址,然后以前安装的模块都安装在Scripts文件夹里,都能导入
我把pyinstaller也安装在这里了
这是安装时候出现的话,应该是安装成功了:
Requirement already satisfied: pyinstaller in c:\users\86189\appdata\local\programs\python\python38-32\lib\site-packages (3.6)
Requirement already satisfied: altgraph in c:\users\86189\appdata\local\programs\python\python38-32\lib\site-packages (from pyinstaller) (0.17)
Requirement already satisfied: setuptools in c:\users\86189\appdata\local\programs\python\python38-32\lib\site-packages (from pyinstaller) (41.2.0)
Requirement already satisfied: pywin32-ctypes>=0.2.0 in c:\users\86189\appdata\local\programs\python\python38-32\lib\site-packages (from pyinstaller) (0.2.0)
Requirement already satisfied: pefile>=2017.8.1 in c:\users\86189\appdata\local\programs\python\python38-32\lib\site-packages (from pyinstaller) (2019.4.18)
Requirement already satisfied: future in c:\users\86189\appdata\local\programs\python\python38-32\lib\site-packages (from pefile>=2017.8.1->pyinstaller) (0.18.2)
WARNING: You are using pip version 19.2.3, however version 20.1.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

Twilight6 发表于 2020-6-5 11:19:22

胡天赐啊 发表于 2020-6-5 11:17
应该安装成功了呀,我环境没设置好,以前的东西都是安装在C:%users\86189\AppData\Local\Programs\Python ...

没有成功   出现 succeefuly 才是 安装成功
升级下PIP然后重新安装 pyinstaller
python -m pip install --upgrade pip

胡天赐啊 发表于 2020-6-5 12:15:49

Twilight6 发表于 2020-6-5 11:19
没有成功   出现 succeefuly 才是 安装成功
升级下PIP然后重新安装 pyinstaller

终于弄好了,打包时又出现这个:struct.error: unpack requires a buffer of 16 bytes结构错误:解包需要16字节的缓冲区
{:10_266:}
dist里面是空的

胡天赐啊 发表于 2020-6-5 12:54:22

胡天赐啊 发表于 2020-6-5 12:15
终于弄好了,打包时又出现这个:struct.error: unpack requires a buffer of 16 bytes结构错误:解包 ...

我知道啦,是图标错了{:10_256:}
页: [1]
查看完整版本: 能不能把自己编的python包装成可执行文件发送出去