My program contains mayavi, traits and pyqt5 elements in order to visualize something in 3D. I tried to convert my GUI-Application with cx_Freeze and it created the exe-file ,but running it I got the error:
no traitsui.toolkits plugin found for toolkit qt4
After some google and stackoverflow research I figured out that it might has something to do with my environment: see creating standalone exe using pyinstaller with mayavi import
According to the suggestions in further google research I added these lines to the top of my code:
import imp
try:
imp.find_module('pyside') # test if PySide if available
except ImportError:
os.environ['QT_API'] = 'pyqt' # signal to pyface that PyQt4 should be used
Following the discussing in the stackoverflow-thread I end up with downloading "Jannick"'s executable. Than I removed the line in my code which is responsible for adding the mayavi scene to the GUI (for testing purposes):
self.ui = Visualization().edit_traits(parent=self,
kind='subpanel').control
Visualization() is the class where I do the actual visualization with mayavi... Then I executed cx_Freeze, my setup.py is:
import sys
import os
os.environ['TCL_LIBRARY'] = "C:\\Users\\Albo\Anaconda3\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Users\\Albo\Anaconda3\\tcl\\tk8.6"
from cx_Freeze import setup, Executable
import cx_Freeze.hooks
build_exe_options = {"packages": ['pygments.lexers', 'tvtk.pyface.ui.qt4','pkg_resources._vendor',
'mayavi', 'traits', 'traitsui', 'sip',
'traitlets','tvtk.vtk_module','traits.api','traitsui.api','os','gui','gui.gui_mayavi', 'tvtk.vtk_module',
'pyface.qt','pyface.qt.QtGui','pyface.qt.QtCore','numpy'],
"includes":['gui','gui.gui_mayavi','mayavi','PyQt5'],
}
executables = [
Executable('main.py', targetName='main.exe',base = 'Win32GUI',)
]
setup(name='main',
version='1.0',
description='',
executables=executables,
options={"build_exe":build_exe_options},
)
Now I had a new error, which is:
RuntimeError: No pyface.toolkits plugin found for toolkit qt4
Now something strange happened... I copied from "Jannick"s project the pyface folder and replaced in in my build (which has been created from cx_Freeze). My exe-file was running without any problems! I was very happy and I thought okay I just add the line which is for the visualization again and then I copy again the pyface folder and it will run. But now I get an error again which I cannot understand at all:
File "C:\Users\xxx\Desktop\xxx\xxx\xxx.py", line 300, in initUI
rightlayout.addWidget(self.ui)
TypeError: addWidget(self, QWidget, stretch: int = 0, alignment: Union[Qt.Alignment, Qt.AlignmentFlag] = Qt.Alignment()): argument 1 has unexpected type 'PySide.QtGui.QWidget'
I also realized that I cannot run the script from console but from spyder it's no problem. I think it has still something to do with the environment because if I remove the lines at the top of the code, it works again...