python.exe文件赢得';t打开/运行
我用visualstudio代码编写了一个python文件,其中anaconda作为解释器。我使用pyinstaller将文件转换为exe,但当我尝试打开exe时,cmd窗口会闪烁打开一秒钟,然后关闭。我不知道它为什么打不开。我的程序应该从HDF5文件中读取并打印用户请求的特定数据,它在VisualStudio代码中正是这样做的。我真的需要一种方法,使它能够运行的人在不同的计算机上与python没有安装 这是我的全部代码,我知道这可能很糟糕,因为我没有太多python经验,但它在visual studio代码中工作:python.exe文件赢得';t打开/运行,python,anaconda,conda,pyinstaller,Python,Anaconda,Conda,Pyinstaller,我用visualstudio代码编写了一个python文件,其中anaconda作为解释器。我使用pyinstaller将文件转换为exe,但当我尝试打开exe时,cmd窗口会闪烁打开一秒钟,然后关闭。我不知道它为什么打不开。我的程序应该从HDF5文件中读取并打印用户请求的特定数据,它在VisualStudio代码中正是这样做的。我真的需要一种方法,使它能够运行的人在不同的计算机上与python没有安装 这是我的全部代码,我知道这可能很糟糕,因为我没有太多python经验,但它在visual s
import numpy as np
import h5py
print ("Make sure to move the HDF file to the folder where this program is located.")
valid = "valid"
#gets the file name and checks if file exists
while valid == "valid":
filename = input("\nwhat is the name of the HDF file including the .hdf: ")
try:
with h5py.File(filename,"r") as hdf:
path = hdf.get("/Results/Unsteady/Output/Output Blocks/Base Output/Unsteady Time Series/2D Flow Areas/Flow Area")
break
except IOError:
print ("File not found")
#opens file
with h5py.File(filename,"r") as hdf:
#navigates to file location
path = hdf.get("/Results/Unsteady/Output/Output Blocks/Base Output/Unsteady Time Series/2D Flow Areas/Flow Area")
path_items = list(path.items())
#keeps running until user tells it to stop
run = "y"
while run == "y" or run == "Y" or run == "yes" or run == "Yes":
#user input
while valid == "valid":
choice = input("\nWhich file would you like to get data from? Depth, Face Shear stress, Face Velocity, or Water Surface: ")
choice = choice.lower()
if choice == "depth" or choice == "face shear stress" or choice == "face velocity" or choice == "water surface":
break
else:
print ("Invalid")
#checks the user input then converts the data set into a numpy array
if choice == "depth":
dataset = np.array(path.get("Depth"))
if choice == "face shear stress":
dataset = np.array(path.get("Face Shear Stress"))
if choice == "face velocity":
dataset = np.array(path.get("Face Velocity"))
if choice == "water surface":
dataset = np.array(path.get("Water Surface"))
#gets the shape/size of the dataset
shape = str(dataset.shape)
shape = shape.replace("(","")
shape = shape.replace(")","")
shape = shape.split(",")
timeAmount = shape[0]
pointAmount = shape[1]
timeAmount = int(timeAmount)
pointAmount = int(pointAmount)
timeAmount -= 1
pointAmount -= 1
print ("\nThis data set has",timeAmount,"time values and",pointAmount,"data values.")
#user input
while valid == "valid":
time = input("\nEnter a single time step: ")
try:
int(time)
break
except ValueError:
print ("Invalid")
time = int(time)
while valid == "valid":
minR = input("\nEnter the first (smaller) value in a range of cell locations: ")
try:
int(minR)
break
except ValueError:
print ("Invalid")
minR = int(minR)
while valid == "valid":
maxR = input("\nEnter the second (larger) value in a range of cell locations: ")
try:
int(maxR)
break
except ValueError:
print ("Invalid")
maxR = int(maxR)
#calculates all the numbers in the range between the two numbers
rangeL = []
while minR != maxR:
rangeL.append(minR)
minR += 1
rangeL.append(maxR)
#prints the value at each point
count = 0
for x in range(len(rangeL)):
tempN = rangeL[count]
tempV = dataset[time,rangeL[count]]
print (str(tempN) + "," + str(tempV))
count += 1
#asks the user if they want to get more data
run = input("\nWould you like to enter more parameters to get more/different data? (y/n): ")
if run == "y" or run == "Y" or run == "yes" or run == "Yes":
pass
else:
print ("Goodbye")
break
可能是因为您有一个只有几个输出的代码。这意味着程序执行这些行非常快,并最终关闭。在代码末尾请求输入。这将使程序保持开放状态。它对我有效。我在命令中使用了pyinstaller
pyinstaller-F file\u name.py
。它起作用了。无法快速关闭并请求输入。能否共享有关您的环境的一些信息?例如,您使用的是什么软件包?Larooga您必须为信息提供除此之外的途径。欢迎来到社区,但为了让我们有效地帮助您,您需要更详细地了解您的问题。参见SO的“重大问题”信息: