我有这个要转换为可执行文件的有效py文件。我使用pyinstaller来做到这一点,具体来说,我使用了此命令
pyinstaller --onefile --windowed --icon=images.ico file.py
实际上,它在dist文件夹中创建了一个可执行文件。但是,当我运行此可执行文件时,会发生错误,显示“无法执行脚本”或有时什么也没有发生。如何成功转换并运行
注意:py文件包含pyqt5和pandas模块。以下是py文件。
import os, sys
import pandas as pd
from PyQt5.QtWidgets import QApplication, QWidget, QLineEdit, QLabel,QVBoxLayout, QHBoxLayout,QPushButton, QMessageBox from PyQt5
import QtGui, QtCore from PyQt5.QtGui import QIcon, QPixmap
class App(QWidget):
def __init__(self):
super().__init__()
self.title = 'Edit CSV'
self.left = 10
self.top = 10
self.width = 640
self.height = 480
self.initUI()
self.setFixedSize(400, 650)
self.setWindowIcon(QIcon('images.png'))
label_input = QLabel("Enter the filename of CSV that you want edit:")
label_input.setFont(QtGui.QFont("Times", 18))
self.input = QLineEdit(self)
self.input.setFont(QtGui.QFont("Times", 18))
self.input.setMaximumWidth(350)
labelImage = QLabel(self)
self.pixmap = QPixmap("stn.png")
labelImage.setPixmap(self.pixmap)
label_output = QLabel("Enter the desired output filename of CSV")
label_output.setFont(QtGui.QFont("Times", 18))
self.output = QLineEdit(self)
self.output.setFont(QtGui.QFont("Times", 18))
self.output.setMaximumWidth(350)
but_edit = QPushButton("edit", self)
but_edit.setMaximumWidth(60)
but_edit.setFont(QtGui.QFont("Times", 18))
layout = QVBoxLayout()
layoutHpic = QHBoxLayout()
layoutH = QHBoxLayout()
layout.addWidget(label_input)
layout.addWidget(self.input)
layout.addStretch()
layoutHpic.addStretch()
layoutHpic.addWidget(labelImage)
layoutHpic.addStretch()
layout.addLayout(layoutHpic)
layout.addStretch()
layout.addWidget(label_output)
layout.addWidget(self.output)
layoutH.addStretch()
layoutH.addWidget(but_edit)
layoutH.addStretch()
layout.addLayout(layoutH)
self.setLayout(layout)
def edit_csv():
input_file = self.input.text().strip()
output_file = self.output.text().strip()
if input_file == "":
QMessageBox.information(self, "Message", "Please choose a file!")
return
elif os.path.exists(input_file) == False:
QMessageBox.about(self, "titt!", "File does not exist")
return
else:
df = pd.read_csv(self.input.text())
df = df.sort_values(["strLocal", "strTide"])
df['strLocal'] = pd.to_datetime(df.strLocal)
df['strLocal'] = df['strLocal'].dt.strftime('%m/%d/%Y %H:%M:%S')
df['strTide'] = df.strTide / 1000 * 0.1
df[['Date','Time']] = df.strLocal.str.split(" ",expand=True)
cols = df.columns.tolist()
cols = cols[2:] + [cols[1]]
df = df[cols]
print(df)
df.to_csv(output_file,index = False, header = False)
QMessageBox.about(self, "titt!", "Done. " + output_file + " was created.")
but_edit.clicked.connect(edit_csv)
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())