.py to.exe 打不开
.py to.exe not opening
我尝试使用 pyinstaller 将 .py 转换为 .exe,我导入的模块是 numpy 和数学控制台 window 打开然后立即关闭。控制台 windows 显示此
回溯(最近调用最后):
文件 "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')
提前致谢
使用 pyinstaller 尝试这些不同的命令,因为我已经尝试了您的代码并制作了一个 .exe 文件并且它可以正常工作。
转到您的 .py 文件所在的当前目录。按下 shift 键,然后按下右键,select 在此处打开 powershell window。然后尝试这些不同的命令。
pyinstaller matrix.py --> (executable file with some other configuration file)
pyinstaller -F matrix.py --> (only executable file)
我尝试使用 pyinstaller 将 .py 转换为 .exe,我导入的模块是 numpy 和数学控制台 window 打开然后立即关闭。控制台 windows 显示此
回溯(最近调用最后): 文件 "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')
提前致谢
使用 pyinstaller 尝试这些不同的命令,因为我已经尝试了您的代码并制作了一个 .exe 文件并且它可以正常工作。
转到您的 .py 文件所在的当前目录。按下 shift 键,然后按下右键,select 在此处打开 powershell window。然后尝试这些不同的命令。
pyinstaller matrix.py --> (executable file with some other configuration file)
pyinstaller -F matrix.py --> (only executable file)