我从Pyqt4切换到Pyqt5,从python2.7切换到3.4,我在Pyqt5中发现了一个bug,所以我把它升级到了python3.4不支持的最新版本。然后我使用python3.5,除了一个名为pymaxwell的模块之外,它工作得很好。总是应用程序崩溃和关闭,为了确认我返回到pyqt4 2.7,我使用python2.7的pyqt5和相同的错误;应用程序立即关闭,并显示代码中与python2.7工作良好的部分中的错误。在gif中,比较了Pyqt4/Pyqt5和python2.7
比较

代码中有问题的部分:
self.btnMXSmxm()
self.mxs_filt.setChecked(True)
self.show_folder.setChecked(False)
inPath = self.input_mxs_scene_2.text();
self.input_mxs_scene.setText(inPath);
self.mxm_list.clear()
if len(inPath) == 0:
self.chosen_material.clear()
# loop over all mxs
else:
mxsList = self.input_mxs_scene.text()
print mxsList
if not len(mxsList) == 0:
scene = Cmaxwell(mwcallback);
ok = scene.readMXS(mxsList);
sceneMaterials = scene.getMaterialNames();
materialcount = int(scene.getMaterialsCount()[0])
if os.path.isfile(self.input_mxs_scene.text()):
for name in sceneMaterials:
scenematerial = scene.getMaterial(name)发布于 2017-10-06 23:09:43
问题解决了;我现在使用python 3.5.4和pyqt 5.9,即使我使用read(file)或read(str(file))也不会给出任何错误。我发现对于pyqt5,它需要对代码中的一些行进行新的排列。我修改了代码,它就可以工作了:
mxsList = self.input_mxs_scene.text()
scene = Cmaxwell(mwcallback)
materialcount = int(scene.getMaterialsCount()[0])
if not len(inPath) == 0:
if os.path.isfile(self.input_mxs_scene.text()):
ok = scene.readMXS(mxsList)
sceneMaterials = scene.getMaterialNames()
if not len(mxsList) == 0:
for name in sceneMaterials:
scenematerial = scene.getMaterial(name)
# #print scenematerial
self.mxm_list.addItem(name)我还添加了: from PyQt5.QtCore import *,它解决了读取媒体文件的其他问题
在多次尝试不同版本的python和pyqt5之后,最好的版本可以很好地协同工作,Python2.7.9和pyqt5来自github:PyQt 5.7.1 for Python 2.7
https://stackoverflow.com/questions/46596986
复制相似问题