python转exe文件闪退_python把项目文件打成exe包

(1)安装python的打包工具 pyinstaller

pip install pyinstaller  -i https://mirrors.aliyun.com/pypi/simple/

e8ccc565ef11ff14cf8f9deec1ee5cac.png

(2)编写代码Persion.py、main.py

Persion.py文件内容

class Persion():
    def __init__(self,name,age):
        self.name = name
        self.age = age
        
        
    def say_hello(self):
        print("hello , ",self.name," " ,self.age)
        
        
    
if __name__ == "__main__":
    persion = Persion("tony",14)
    persion.say_hello()

main.py文件是程序的入口, 其内容如下所示

from Persion import Persion


print("hi, I form exe ")


persion = Persion("tony",14)
persion.say_hello()


read_line = input("任意键退出")

(3)把 Persion.py、main.py 文件复制到目录 from_exe_demo中

6682a98f5c7716d1824849521e222f84.png

(4)进入目录 from_exe_demo中

20955fee96a0f6f9210035ef3da82fef.png

(5)执行打包命令,main.py是程序入口的主类

pyinstaller.exe -D main.py

70c437fa08d988a4535fdc9e1ef7cbab.png

(6)打包结果在下面的dist/main目录中

be994d759f7fa3c04671dad9b5d955fa.png

(7)如果有配置文件,手动把配置文件复制到 dist/main中。鼠标双击 main.exe,执行结果如下图所示

72cb809b971d5e5a67a9a8c65d3b506f.png

参考 https://zhuanlan.zhihu.com/p/62915660

https://zhuanlan.zhihu.com/p/58199926

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值