【问题记录】python的py文件生成exe可执行程序闪退

今天想弄一下这个,记录一下过程:
1.
pip install pyinstaller -i https://pypi.tuna.tsinghua.edu.cn/simple
pyinstaller vei.py
执行这个之后生成了build目录和exe文件,但发现exe存在闪退问题:
在这里插入图片描述
查了一下说缺少相关包,继续下载:
pip install pypiwin32 -i https://pypi.tuna.tsinghua.edu.cn/simple

https://www.lfd.uci.edu/~gohlke/pythonlibs/#pycairo下载相关包复制到当前项目下:
pip install pycairo-1.20.0-cp39-cp39-win_amd64.whl

在这里插入图片描述
pip install PyQt5
pip install IPython
pip install wxPython
pip install ipykernel
pip install zmq
一些七七八八的包,也不知道干什么用的,查到有文章说要下载这些包。

然后在命令行输入pyinstaller 说不是可执行程序,于是在命令行全局安装 pip intall pyinstaller
在这里插入图片描述
用参数-F 这样dist下面只有exe文件
在这里插入图片描述
报错信息显示PIL模块找不到,于是:安装PIL显示失败,于是安装pillow
C:\Windows\system32>pip install PIL
ERROR: Could not find a version that satisfies the requirement PIL
ERROR: No matching distribution found for PIL

C:\Windows\system32>pip install Pillow
Collecting Pillow
Using cached Pillow-8.1.1-cp39-cp39-win_amd64.whl (2.2 MB)
Installing collected packages: Pillow
Successfully installed Pillow-8.1.1
不知道执行这个exe还是显示模块找不到,于是重新写了一个py文件再次打包:
已经可以执行了。说明运行exe成功。
在这里插入图片描述

另外运行一段修改png为jpg的拒绝访问问题:

import os

from PIL import Image
import cv2 as cv
def PNG_JPG(PngPath):
    img = cv.imread(PngPath, 0)
    w, h = img.shape[::-1]
    infile = PngPath
    outfile = os.path.splitext(infile)[0] + ".jpg"
    img = Image.open(infile)
    img = img.resize((int(w / 2), int(h / 2)), Image.ANTIALIAS)
    try:
        if len(img.split()) == 4:
            # prevent IOError: cannot write mode RGBA as BMP
            r, g, b, a = img.split()
            img = Image.merge("RGB", (r, g, b))
            img.convert('RGB').save(outfile, quality=70)
            os.remove(PngPath)
        else:
            img.convert('RGB').save(outfile, quality=70)
            os.remove(PngPath)
        return outfile
    except Exception as e:
        print("PNG转换JPG 错误", e)


path_root = os.getcwd()
Path= 'C:\\Users\\pic\\'
img_dir = os.listdir(Path)
for img in img_dir:
    if img.endswith('.png'):
        PngPath= Path + img
        PNG_JPG(PngPath)
img_dir = os.listdir(Path)
for img in img_dir:
    print(img)

一开始一直报错显示permission denied
方法:用管理员身份运行pycharm就好了
再次打开文件,后缀已经修改。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值