吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1069|回复: 15
收起左侧

[求助] pyinstaller打包的exe运行不了

[复制链接]
smileat2000 发表于 2022-8-18 23:51
这是打包界面

这是运行闪退前1秒

在VSCode和cmd里运行.py文件都正常,就是pyinstaller -F打包成一个exe之后就运行不了,求解

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

wty3025 发表于 2022-8-19 00:09
用pyinstaller -F -w 试试
 楼主| smileat2000 发表于 2022-8-19 00:36
wty3025 发表于 2022-8-19 00:09
用pyinstaller -F -w 试试

写的就是控制台程序。。-W了还怎么运行啊。
icodeme 发表于 2022-8-19 00:52
 楼主| smileat2000 发表于 2022-8-19 00:55
icodeme 发表于 2022-8-19 00:52
楼主方便把代码发出来让我试一试吗

[Python] 纯文本查看 复制代码
import os
import cv2
import subprocess


def read():  # 读取图片
    for file in os.listdir(os.getcwd()):
        if file.endswith("png") or file.endswith("jpg") or file.endswith("jpeg") or file.endswith(
                "png") or file.endswith("tif") or file.endswith("tiff"):
            break
    return file


def rsz(img, w, h):  # 修改尺寸
    n = cv2.resize(img, (w, h), interpolation=cv2.INTER_AREA)
    return n


def cmd(shell):  # 不显示控制台窗口
    subprocess.call(shell,
                    creationflags=0x00000008)
    return


def qg(ns, names):  # 切割
    i = 0
    while i < len(names):
        cv2.imwrite(names[i], ns[i], [cv2.IMWRITE_TIFF_RESUNIT, 3,
                                      cv2.IMWRITE_TIFF_XDPI, 100, cv2.IMWRITE_TIFF_YDPI, 100])
        i = i + 1
    return


def re(names):  # 删除
    i = 0
    while i < len(names):
        os.remove(names[i])
        i = i + 1
    return


if __name__ == "__main__":  # 入口
    file = read()
    lname = os.path.splitext(file)[-1]
    os.rename(file, "img" + lname)
    img = cv2.imread("img" + lname)
    os.rename("img" + lname, file)


def xz():  # 选择
    k = input("\n    " + read() + """\n

    1.三联画160x60(40x60 80x60 40x60)

    2.三联画200x70(50x70 100x70 50x70)

    3.三联画240x80(60x80 120x80 60x80)

    4.三联画280x90(70x90 140x90 70x90)

    5.四联画140x90(30x60 40x80 40x80 30x60)

    6.四联画180x110(40x80 50x100 50x100 40x80)

    7.四联画220x130(50x100 60x120 60x120 50x100)

    8.五联画1100x75(30x45 30x60 30x75 30x60 30x45)

    9.五联画200x100(40x60 40x80 40x100 40x80 40x60)

    10.五联画250x120(50x80 50x100 50x120 50x100 50x80)

    请选择:""")
    return k


match xz():
    case '1':  # 三联画160x60(40x60 80x60 40x60)
        n = rsz(img, 16000, 6000)
        qg((n[0:6000, 0:4000], n[0:6000, 4000:12000], n[0:6000,
                                                      12000:16000]), ('A40x60.tif', 'B80x60.tif', 'C40x60.tif'))
        cmd('magick A40x60.tif B80x60.tif C40x60.tif -bordercolor black -resize 10% ABCDE.png')
        cmd(
            'magick -background None -gravity center xc:none[100x] ABCDE-0.png xc:none[100x] ABCDE-1.png xc:none[100x] ABCDE-2.png xc:none[100x] +append A.png')
        re(('ABCDE-0.png', 'ABCDE-1.png',
            'ABCDE-2.png'))
    case '2':  # 三联画200x70(100x70 100x70 100x70)
        n = rsz(img, 20000, 7000)
        qg((n[0:7000, 0:5000], n[0:7000, 5000:15000], n[0:7000, 15000:20000]),
           ('A100x70.tif', 'B100x70.tif', 'C100x70.tif'))
        cmd('magick A100x70.tif B100x70.tif C100x70.tif -bordercolor black -resize 10% ABCDE.png')
        cmd(
            'magick -background None -gravity center xc:none[100x] ABCDE-0.png xc:none[100x] ABCDE-1.png xc:none[100x] ABCDE-2.png xc:none[100x] +append A.png')
        re(('ABCDE-0.png', 'ABCDE-1.png',
            'ABCDE-2.png'))
    case '3':  # 三联画240x80(60x80 120x80 60x80)
        n = rsz(img, 24000, 8000)
        qg((n[0:8000, 0:6000], n[0:8000, 6000:18000], n[0:8000, 18000:24000]),
           ('A60x80.tif', 'B120x80.tif', 'C60x80.tif'))
        cmd('magick A60x80.tif B120x80.tif C60x80.tif -bordercolor black -resize 10% ABCDE.png')
        cmd(
            'magick -background None -gravity center xc:none[100x] ABCDE-0.png xc:none[100x] ABCDE-1.png xc:none[100x] ABCDE-2.png xc:none[100x] +append A.png')
        re(('ABCDE-0.png', 'ABCDE-1.png',
            'ABCDE-2.png'))
    case '4':  # 三联画280x90(70x90 140x90 70x90)
        n = rsz(img, 28000, 9000)
        qg((n[0:9000, 0:7000], n[0:9000, 7000:21000], n[0:9000, 21000:28000]),
           ('A70x90.tif', 'B140x90.tif', 'C70x90.tif'))
        cmd('magick A70x90.tif B140x90.tif C70x90.tif -bordercolor black -resize 10% ABCDE.png')
        cmd(
            'magick -background None -gravity center xc:none[100x] ABCDE-0.png xc:none[100x] ABCDE-1.png xc:none[100x] ABCDE-2.png xc:none[100x] +append A.png')
        re(('ABCDE-0.png', 'ABCDE-1.png',
            'ABCDE-2.png'))
    case '5':  # 四联画140x90(30x60 40x80 40x80 30x60)
        n = rsz(img, 14000, 9000)
        qg((n[2000:8000, 0:3000], n[1000:9000, 3000:7000], n[0:8000, 7000:11000],
            n[1000:7000, 11000:14000]), ('A30x60.tif', 'B40x80.tif', 'C40x80.tif', 'D30x60.tif'))
    case '6':  # 四联画180x110(40x80 50x100 50x100 40x80)
        n = rsz(img, 18000, 11000)
        qg((n[2000:10000, 0:4000], n[1000:11000, 4000:9000], n[0:10000, 9000:14000],
            n[1000:9000, 14000:18000]), ('A40x80.tif', 'B50x100.tif', 'C50x100.tif', 'D40x80.tif'))
    case '7':  # 四联画220x130(50x100 60x120 60x120 50x100)
        n = rsz(img, 22000, 13000)
        qg((n[2000:12000, 0:5000], n[1000:13000, 5000:11000], n[0:12000, 11000:17000],
            n[1000:11000, 17000:22000]), ('A50x100.tif', 'B60x120.tif', 'C60x120.tif', 'D50x100.tif'))
    case '8':  # 五联画1100x75(30x45 30x60 30x75 30x60 30x45)
        n = rsz(img, 15000, 7500)
        qg((n[1500:6000, 0:3000], n[750:6750, 3000:6000], n[0:7500, 6000:9000], n[750:6750, 9000:12000],
            n[1500:6000, 12000:15000]), ('A30x45.tif', 'B30x60.tif', 'C30x75.tif', 'D30x60.tif', 'E30x45.tif'))
        cmd('magick A30x45.tif B30x60.tif C30x75.tif D30x60.tif E30x45.tif -bordercolor black -resize 10% ABCDE.png')
        cmd('magick -background None -gravity center xc:none[100x] ABCDE-0.png xc:none[100x] ABCDE-1.png xc:none[100x] ABCDE-2.png xc:none[100x] ABCDE-3.png xc:none[100x] ABCDE-4.png xc:none[100x] +append A.png')
        re(('ABCDE-0.png', 'ABCDE-1.png',
            'ABCDE-2.png', 'ABCDE-3.png', 'ABCDE-4.png'))
    case '9':  # 五联画200x100(40x60 40x80 100x100 40x80 40x60)
        n = rsz(img, 20000, 10000)
        qg((n[2000:8000, 0:4000], n[1000:9000, 4000:8000], n[0:10000, 8000:12000], n[1000:9000, 12000:16000],
            n[2000:8000, 16000:20000]), ('A40x60.tif', 'B40x80.tif', 'C40x100.tif', 'D40x80.tif', 'E40x60.tif'))
        cmd('magick A40x60.tif B40x80.tif C40x100.tif D40x80.tif E40x60.tif -bordercolor black -resize 10% ABCDE.png')
        cmd('magick -background None -gravity center xc:none[100x] ABCDE-0.png xc:none[100x] ABCDE-1.png xc:none[100x] ABCDE-2.png xc:none[100x] ABCDE-3.png xc:none[100x] ABCDE-4.png xc:none[100x] +append A.png')
        re(('ABCDE-0.png', 'ABCDE-1.png',
            'ABCDE-2.png', 'ABCDE-3.png', 'ABCDE-4.png'))
    case '10':  # 五联画250x120(50x80 50x100 50x120 50x100 50x80)
        n = rsz(img, 25000, 12000)
        qg((n[2000:10000, 0:5000], n[1000:11000, 5000:10000], n[0:12000, 10000:15000], n[1000:11000, 15000:20000],
            n[2000:10000, 20000:25000]), ('A50x80.tif', 'B50x100.tif', 'C50x120.tif', 'D50x100.tif', 'E50x80.tif'))
        cmd('magick A50x80.tif B50x100.tif C50x120.tif D50x100.tif E50x80.tif -bordercolor black -resize 10% ABCDE.png')
        cmd('magick -background None -gravity center xc:none[100x] ABCDE-0.png xc:none[100x] ABCDE-1.png xc:none[100x] ABCDE-2.png xc:none[100x] ABCDE-3.png xc:none[100x] ABCDE-4.png xc:none[100x] +append A.png')
        re(('ABCDE-0.png', 'ABCDE-1.png',
            'ABCDE-2.png', 'ABCDE-3.png', 'ABCDE-4.png'))
 楼主| smileat2000 发表于 2022-8-19 00:57
icodeme 发表于 2022-8-19 00:52
楼主方便把代码发出来让我试一试吗

在线等!急!
JUNGLE_CN 发表于 2022-8-19 01:04
打包的依赖问题 cv2 opencv 手动改一下打包过程中有一个生成文件 添加进去重新打包
 楼主| smileat2000 发表于 2022-8-19 01:36
JUNGLE_CN 发表于 2022-8-19 01:04
打包的依赖问题 cv2 opencv 手动改一下打包过程中有一个生成文件 添加进去重新打包

pyinstaller -–clean -F -i icon.ico a.py C:\Users\Administrator\AppData\Local\Programs\Python\Python310\Lib\site-packages\cv2

这样把opencv的目录加进去打包还是不行
 楼主| smileat2000 发表于 2022-8-19 02:16
解决了,呜呜呜,原来是opencv版本太高的原因,降了个版本就正常了,呜呜呜,搞了一天,电脑系统都重装了,
iawyxkdn8 发表于 2022-8-19 08:10
opencv版本太高!!
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-25 04:48

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表