.py to.exe не открывается - PullRequest
       12

.py to.exe не открывается

0 голосов
/ 26 апреля 2020

Я попытался выполнить преобразование .py в .exe с помощью pyinstaller, импортированные мной модули numpy и математическое окно консоли открывается, а затем сразу же закрывается. Консоль windows показывает это

Traceback (последний вызов был последним): файл "matrix.py", строка 1, при импорте numpy как np ModuleNotFoundError: Нет модуля с именем 'numpy' [18864 ] Не удалось выполнить скрипт

...... Пожалуйста, помогите:)

КОД:

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')

Заранее спасибо

1 Ответ

1 голос
/ 26 апреля 2020

Попробуйте эти разные команды с pyinstaller, потому что я попробовал ваш код и создал файл .exe и его работу.

Go в текущую директорию, куда выходит ваш файл .py. Нажмите кнопку Shift, а затем нажмите правую кнопку мыши, выберите здесь открытое окно PowerShell. и затем попробуйте эти другие команды.

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