所以我在PyCharm中创建了一个模块,它在PyCharm中工作得很好,因为PyCharm通过自己运行这个代码来修复系统路径:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(608, 173)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
self.gridLayout = QtWidgets.QGridLayout()
self.gridLayout.setObjectName("gridLayout")
self.verticalLayout.addLayout(self.gridLayout)
self.addFileBtn_0 = QtWidgets.QPushButton(self.centralwidget)
self.addFileBtn_0.setObjectName("addFileBtn_0")
self.gridLayout.addWidget(self.addFileBtn_0, 0, 0, 1, 1)
self.lineEditFile_0 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEditFile_0.setText("")
self.lineEditFile_0.setObjectName("lineEditFile_0")
self.gridLayout.addWidget(self.lineEditFile_0, 0, 1, 1, 1)
self.addFileBtn_1 = QtWidgets.QPushButton(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.addFileBtn_1.sizePolicy().hasHeightForWidth())
self.addFileBtn_1.setSizePolicy(sizePolicy)
self.addFileBtn_1.setObjectName("addFileBtn_1")
self.gridLayout.addWidget(self.addFileBtn_1, 1, 0, 1, 1)
self.lineEditFile_1 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEditFile_1.setObjectName("lineEditFile_1")
self.gridLayout.addWidget(self.lineEditFile_1, 1, 1, 1, 1)
self.buttonsLayer = QtWidgets.QVBoxLayout()
self.buttonsLayer.setObjectName("buttonsLayer")
self.addFileGroupBtn = QtWidgets.QPushButton(self.centralwidget)
self.addFileGroupBtn.setObjectName("addFileGroupBtn")
self.buttonsLayer.addWidget(self.addFileGroupBtn)
self.saveConfigBtn = QtWidgets.QPushButton(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.saveConfigBtn.sizePolicy().hasHeightForWidth())
self.saveConfigBtn.setSizePolicy(sizePolicy)
self.saveConfigBtn.setObjectName("saveConfigBtn")
self.buttonsLayer.addWidget(self.saveConfigBtn)
self.gridLayout.addLayout(self.buttonsLayer, 2, 0, 1, 2)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 24))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
这意味着我无法从终端运行该模块,因为我没有在该模块中的每个脚本中扩展sys路径。有没有办法以自动方式为该模块中的每个脚本扩展系统路径,如PyCharm,而无需在每个文件中执行一堆sys.path.extend。