简体   繁体   中英

Python build exe file runs successfully in conda prompt but gets quit while running

Here is the code,

from pymatting import *
#import numpy as np
import tkinter as tk
root = tk.Tk()


def func():
    print( "before matting")
    scale = 1
    print( "1")
    image = load_image(r"s.png", "RGB", scale, "box")
    trimap = load_image(r"tri.png", "GRAY", scale, "nearest")
    print( "2")
    # estimate alpha from image and trimap
    alpha = estimate_alpha_knn(image, trimap)
    
    print( "3")
    # estimate foreground from image and alpha
    foreground = estimate_foreground_ml(image, alpha, return_background=False)
    print( "4")
    # save cutout
    cutout = stack_images(foreground, alpha)
    
    save_image("2_out.png", cutout)   
    print( "saved")
    
button = tk.Button(root, text = "start",command =func) 
button.pack() 
root.mainloop()

I have build the exe using pyinstaller like

pyinstaller --hidden-import six --hidden-import='pkg_resources.py2_warn' --hidden-import pymatting main.py

it gets build successfully, and using in conda prompt ./main.exe I can able to view the output..

But this code keeps failing when main.exe open directly using windows. It exits while doing it.. Program quits without showing any error..

(i think that linear solving equations of numpy functions are not getting included in the build, such as numpy.inner or numpy.linalg etc. on my anlaysis, sorry if i am wrong)

Suggest me a way to solve this. this is the original image 1 and its trimap 2

The real problem is pymatting uses to numpy functions np.linalg.norm and np.inner , these two caused the real time application to exit. I replaced both the functions with alternatives scipy.linalg.norm and manual inner function . Pyinstaller or cx_freeze will not take these two functions while building the app. So its fails outside the conda prompt environment

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM