Delrius Euphoria
Delrius Euphoria

Reputation: 15098

.py to.exe not opening

I tried doing a .py to .exe conversion using pyinstaller, modules i imported are numpy and maths the console window opens and then closes immediately. The console windows shows this

Traceback (most recent call last): File "matrix.py", line 1, in import numpy as np ModuleNotFoundError: No module named 'numpy' [18864] Failed to execute script

......Please help :)

CODE:

import numpy as np
import math

add = sub = mul = z = 0

while True:
    print()
    print('Choose option for operations on matrix:')
    print('1. Addition')
    print('2. Subtraction')
    print('3. Multiplication')
    print('4. Determinant')
    print('5. Exit')
    print()

    choice = int(input('Enter your choice: '))
    print()

    if choice == 5:
        print('Successfully Terminated')
        break

    elif choice < 5:

        if choice == 1:
            r = int(input('Enter the number of rows of 1st matrix: '))
            c = int(input('Enter the number of columns of 1st matrix: '))
            a = np.zeros((r,c),dtype=int)

            for i in range(len(a)):
                for j in range(len(a[i])):
                    x = int(input('Enter the element of 1st matrix and press enter: '))
                    a[i][j] = x

            r1 = int(input('Enter the number of rows of 2nd matrix : '))
            c1 = int(input('Enter the number of columns of 2nd matrix : '))
            b = np.zeros((r1,c1),dtype=int)

            for i in range(len(b)):
                for j in range(len(b[i])):
                    x = int(input('Enter the element of 2nd matrix and press enter: '))
                    b[i][j] = x

            add = np.add(a,b)
            print()
            print('The sum of these two matrices are: ')
            print(add)

        elif choice == 2:
            r = int(input('Enter the number of rows of 1st matrix: '))
            c = int(input('Enter the number of columns of 1st matrix: '))
            a = np.zeros((r, c), dtype=int)

            for i in range(len(a)):
                for j in range(len(a[i])):
                    x = int(input('Enter the element of 1st matrix and press enter: '))
                    a[i][j] = x

            r1 = int(input('Enter the number of rows of 2nd matrix : '))
            c1 = int(input('Enter the number of columns of 2nd matrix : '))
            b = np.zeros((r1, c1), dtype=int)

            for i in range(len(b)):
                for j in range(len(b[i])):
                    x = int(input('Enter the element of 2nd matrix and press enter: '))
                    b[i][j] = x

            sub =np.subtract(a,b)
            print()
            print('The Difference of these two matrices are: ')
            print(sub)

        elif choice == 3:
            r = int(input('Enter the number of rows of 1st matrix: '))
            c = int(input('Enter the number of columns of 1st matrix: '))
            a = np.zeros((r, c), dtype=int)

            for i in range(len(a)):
                for j in range(len(a[i])):
                    x = int(input('Enter the element of 1st matrix and press enter: '))
                    a[i][j] = x

            r1 = int(input('Enter the number of rows of 2nd matrix : '))
            c1 = int(input('Enter the number of columns of 2nd matrix : '))
            b = np.zeros((r1, c1), dtype=int)

            for i in range(len(b)):
                for j in range(len(b[i])):
                    x = int(input('Enter the element of 2nd matrix and press enter: '))
                    b[i][j] = x
            if c != r1:
                print()
                print('Sorry, matrix multiplication is not defined for these matrices.')
            else:
                mul =np.matmul(a,b)
                print()
                print('The product of these two matrices are: ')
                print(mul)

        elif choice == 4:
            r = int(input('Enter the number of rows of 1st matrix: '))
            c = int(input('Enter the number of columns of 1st matrix: '))
            if r != c:
                print('It must be a square matrix')
            else:
                a = np.zeros((r, c), dtype=int)

                for i in range(len(a)):
                    for j in range(len(a[i])):
                        x = int(input('Enter the element of matrix and press enter: '))
                        a[i][j] = x
                z = np.linalg.det(a)
                print()
                if z > 0:
                    deter = math.floor(z)
                    print(f'The Determinant of the given matrix is {deter}')
                elif z < 0:
                    deter = math.ceil(z)
                    print(f'The Determinant of the given matrix is {deter}')
                elif z == 0:
                    print(f'The Determinant of the given matrix is {0}')

        else:
            print('Invalid Choice')

Thanks in advance

Upvotes: 0

Views: 151

Answers (1)

Ali Hassan
Ali Hassan

Reputation: 966

Try these different command with pyinstaller, because i have tried your code and made an .exe file and its working.

Go to current directory where your .py file exits. Press shift button and then press right click, select open powershell window here. and then try these different command.

pyinstaller matrix.py --> (executable file with some other configuration file)
pyinstaller -F matrix.py --> (only executable file)

Upvotes: 1

Related Questions