0

I wrote a simple program using PyQt5. I used also th Pynsist to make it execute on other computers. every thing was good, but the problem was when I try to execute the application from the Start Menu! it opens a console and close it very fast.

I made a long search and i tried to do what others did, but i still have the same problem!

This is a part of my code:

import os, sys
import array
import numpy as np
import matplotlib.pyplot as plt
from pandas import read_csv

## second part of import
from PyQt5 import QtWidgets, uic,QtGui,QtCore
from ui import test1
import gc


import statistics


class window(test1.Ui_MainWindow,QtWidgets.QMainWindow):
    x1=[]
    x2 = []
    h=[]
    x1_1 = []
    x1_20 = []
    x_cor = []
    x_graph = []
    x_cal = []
    x_cal_squ =[]
    x_cal_mul = []
    def __init__(self):
            super(window,self).__init__()
            self.setupUi(self)

            self.All()

    def All(self):
            self.toolButton.clicked.connect(self.select_file)
            self.pushButton.clicked.connect(self.correcting)
            self.toolButton_2.clicked.connect(self.graphic_show)
            self.pushButton_3.clicked.connect(self.checked_data)
            self.pushButton_4.clicked.connect(self.calculate)
    def select_file(self):
        if not self.lineEdit.text() == "" and not self.lineEdit_2.text() == "" and not self.lineEdit_3.text() == "":
            if self.lineEdit_3.text() == "32" or self.lineEdit_3.text() == "8":




                file,ext = QtWidgets.QFileDialog.getOpenFileName()
        # reading binary file
                count = int(os.stat(file).st_size/2)   
                statinfo = os.stat(file)

                print(statinfo,"   ",count)
                with open(file, 'rb') as fb:
                    bin_1 = array.array("h")
                    print("sss")
                    bin_1.fromfile(fb, count)


                print(len(bin_1))
                res =''
                Channel_number = int(str(self.lineEdit_3.text()))
                for x in range(1,Channel_number + 1):    # range for 32 bit. for 8 bit the range will be (1,9)
                        y = str(self.lineEdit_2.text())  # folder name
                        y_2 = str(self.lineEdit.text())  # file name
                        folder_path_1 = os.path.isdir(os.getcwd() + '/' + y +'/' + y+'{}'.format(x))
                        if not folder_path_1:
                            folder_path = os.makedirs(os.path.join(os.getcwd(), y + '/' + y +'{}'.format(x)))
        # write the data from every channle to it's folder with txt format        
                for x in range(1,Channel_number + 1):    # range for 32 bit. for 8 bit the range will be (1,9)
                        y = str(self.lineEdit_2.text())
                        folder_name = str(self.lineEdit.text())
                        folder_path_1 = os.path.isdir(os.getcwd() + '/' + y +'/' + y+'{}'.format(x))
                        if not folder_path_1:
                            folder_path = os.makedirs(os.path.join(os.getcwd(), y + '/' + y +'{}'.format(x)))

                        file_name= y_2 +'{}.txt'.format(x)
                        fig_name = y_2 +'{}.png'.format(x)
                        file_name_2 = y_2 + '_new{}.txt'.format(x)
                        fig_name_2 = y_2 + '_new{}.png'.format(x)
                        file_name_3 = 'result{}.txt'.format(x)
                        file_name_20 = y_2 + '_new20.txt'

                        with open (os.path.join(os.getcwd() + '/' + y +'/' + y+'{}'.format(x), file_name),"w") as wf:
                            res += str(x)
                            for n in range(0,len(bin_1),Channel_number):




                                if x == 20:
                                    wf.writelines("{:.2f}\n".format(bin_1[n+(x-1)]*0.65))
                                else:

                                    wf.writelines("{:.2f}\n".format(bin_1[n+(x-1)]*-0.043))

                        with open(os.path.join(os.getcwd() + '/' + y +'/' + y+'{}'.format(x), file_name),'r') as ff:
                                x1 = ff.readlines()


                                x1 = [float(i) for i in x1]
                                x1 = x1
                                x2=x1
                                x1_max = max(x1, key=abs)
                                x1_min = min(x1)

                                x1_sum = sum(x1)

                                x1_av = statistics.mean(x1)
                                x2 = [float(i) for i in x2]
                                listmask=x1_av
                                for num in range(len(x2)):

                                    if x2[num] == x1_max and num >= 0 and num <= int(len(x2)/4):
                                        #print("nummmmmm = :",num)
                                        x2[0:int(len(x2)/4)] = x2[int(3*len(x2)/4):(len(x2))]

                                    elif x2[num] == x1_max and num > int(len(x2)/4) and num <= int(len(x2))/2:
                                         x2[(num-500):(num+int(len(x2)/4))] = x2[(int(3*len(x2)/4)-500):(len(x2))]
                                    elif x2[num] == x1_max and num > int((len(x2))/2) and num <= (int(3*len(x2)/4)):
                                         x2[(num-500):(int(len(x2))-500)] = x2[0:int(len(x2)/2)]
                                         x2[(len(x2)-500):len(x2)] = x2[0:500]



                                    elif x2[num] == x1_max and num >= int(3*len(x2)/4): # and num <= (len(x2)):
                                         x2[int(3*len(x2)/4):len(x2)] = x2[0:int(len(x2)/4)]






                                print(x1_max)
                                xx1_av = statistics.mean(x2)
                                h = (x1_max - xx1_av)


                                #print( xx1_av, x1_av , h)
                                #for n in range(1,33):
                                with open("results_2.txt",'a') as test:

                                   test.writelines("{:.2f}\n".format(h*(-0.043)))

                              #  from pandas import read_csv
                                (read_csv(os.path.join(os.getcwd() + '/' + y +'/' + y+'{}'.format(x), file_name))).plot( color='red')
                                plt.savefig(os.path.join(os.getcwd() + '/' + y +'/' + y+'{}'.format(x), fig_name))
                                #plt.show()

                        with open(os.path.join(os.getcwd() + '/' + y +'/' + y+'{}'.format(x), file_name),"r")  as ff:
                            x1 = ff.readlines()
                            x1 = [float(i) for i in x1]
                            with open(os.path.join(os.getcwd() + '/' + y +'/' + y+'{}'.format(x), file_name_2),"w")  as f:
                                for num in range(len(x1)):
                                    x1[num] = (x1[num] - xx1_av)

                                    f.writelines("{:.2f}\n".format(x1[num]))
        # read the new files and write the results of max in new file for the further analysis
                del x1[:]
                gc.collect()

            else:
                QtWidgets.QMessageBox.information(None, "Error", "Make sure of the channels number!!!")
        else:
            QtWidgets.QMessageBox.information(None, "Error", "Fill all the required information")



......
if __name__ == "__main__":
    app = QtWidgets.QApplication([])
    qt_app = window()
    qt_app.show()
    app.exec_()

and the installer.cfg file:

[Application]
name=PythonApplication12
version=1.0
# How to launch the app - this calls the 'main' function from the 'PythonApplication12' package:
entry_point=test1:Ui_MainWindow
extra_preamble=PythonApplication12.py


console=true


[Python]
version=3.6.7
bitness = 64
include_msvcrt=true


[Include]
# Packages from PyPI that your application requires, one per line
# These must have wheels on PyPI:
pypi_wheels = PyQt5==5.11.3
     numpy==1.16.0
     pandas==0.23.4
     PyQt5==5.13.0
     matplotlib==3.0.2
     PyQt5-sip==4.19.18
Packages = PyQt5
     numpy
     pandas
     matplotlib
     statistics
     tkinter
     _tkinter






# Other files and folders that should be installed
files = ui/test1.py
        ui/__init__.py
        ui/test1.ui
        ui
        PythonApplication12.py
        lib
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Ziad Lucka
  • 63
  • 4
  • This usually happens when there's an error as your program tries to start. The traceback should get written to a log file so you can see what went wrong: https://pynsist.readthedocs.io/en/latest/installers.html#uncaught-exceptions – Thomas K Jul 15 '19 at 15:07
  • thanks for your replaying! – Ziad Lucka Jul 15 '19 at 22:31

1 Answers1

1

The code asked about ('cycler'), then (Matplotlib requires dateutil), (six), (pytz)... I spend all the night reinstalling and adding these packages to the cfg file.... but after all it works! It was much easier to install Python on the other computer...!

The whole problem was with matplotlib!

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Ziad Lucka
  • 63
  • 4
  • One of the decisions I made for Pynsist was that it wouldn't try to automatically follow dependencies, so you have to list all the necessary modules in the cfg file. This is a pain sometimes, but it's a simple pain once you understand it, and I've had bad experiences with tools that do try to do it automatically. I started playing with a [new way to identify required modules](https://pypi.org/project/kartoffel/), but I haven't got round to taking it further than an experiment. – Thomas K Jul 16 '19 at 16:27