python程序打包

https://www.cnblogs.com/gopythoner/p/6337543.html

常用命令:

 

下载包:pyinstaller

1、对于单个.py文件,在cmd窗口,先切换到当前要打包的文件的目录,输入pyinstaller -F 文件名.py

在此目录中会生成3个文件,built,dist,.spec的东西,打包好的东西在dist里面,其他两个没什么用,

但运行会闪退,不知道怎么解决。。。

2、pygame打包的游戏exe

    黑屏,不能运行点击打开链接

3、当pyinstaller使用报没有这个模块这种错误时,可以删了重安装pip uninstall pyinstaller(删除命令)

 

 

gbk报错:

      把文件名改成英文的

 

换图标:

要先生成 .ico 图标,原理:https://www.oschina.net/question/941819_161672

在线生成 ico 网站:http://ico.duduxuexi.com/

打包:pyinstaller -i 图标名.ico -F xx.py

 

Pyinstaller打包出现UnicodeDecodeError: 'utf-8' codec can't decode byte 0xce in position

在你打包的命令行中先输入chcp 65001 然后再输入打包命令。 
pyinstaller -F xxx.py

 

FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\1\\_MEI54762\\jieba\\dict.txt'
[20784] Failed to execute script bat_server

打包后运行,出现这种类似的问题,但明明包都已经安装了,

https://blog.youkuaiyun.com/lucyTheSlayer/article/details/92795220

 

调用外部文件

https://blog.youkuaiyun.com/m0_37477175/article/details/82146996

如要打包成一个文件夹,个使用链接中的方案一

如要打包成可执行文件,先利用方案二读取文件路径:

import os 
import sys
def resource_path(relative_path):
    """ Get absolute path to resource, works for dev and for PyInstaller """
    base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
    return os.path.join(base_path, relative_path)

file = 'text.txt'
print(resource_path(file))  ## <----- 打印一下看看是否在临时文件夹下搜索
with open(resource_path(file), 'r') as f:
    while True:
        line = f.readline()     # 逐行读取
        if not line:
            break
        print(line)

在打包时,直接参数添加:

https://blog.youkuaiyun.com/qq_26373925/article/details/105524318

pyinstaller -F main.py --add-data "nginx.exe;."

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值