我试着用pyinstaller做了一个.py到.exe的转换,我导入的模块是numpy和maths,控制台窗口打开后又马上关闭。控制台窗口显示如下
回溯(最近一次调用)。 文件 "matrix.py",第1行,在import numpy中,作为npModuleNotFoundError.No模块命名为'numpy'[18864] 脚本执行失败。没有名为'numpy'[18864]的模块,执行脚本失败。
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')
先谢谢你
试试这些不同的命令与pyinstaller,因为我已经尝试了你的代码,并作出了一个.exe文件,其工作。
转到你的.py文件退出的当前目录。按shift键,然后按右键,在这里选择打开powerhell窗口,然后尝试这些不同的命令。
pyinstaller matrix.py --> (executable file with some other configuration file)
pyinstaller -F matrix.py --> (only executable file)