4

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...

jpeg
  • 2,372
  • 4
  • 18
  • 31
roflcopter122
  • 165
  • 1
  • 14
  • 2
    It looks like you're mixing PyQt and PySide. – jpeg Oct 15 '18 at 08:43
  • 1
    Maybe try to remove the pyside import test and directly go for os.environ['QT_API'] = 'pyqt'. I am not completely sure anymore but it might be possible that I changed some code in pyface, which you are using now. – Jannick Oct 19 '18 at 08:44
  • Hi and thanks for your answer. I removed the pyside lines and I tried to go with your suggested environment. But after that my script didn't run until I changed to os.environ['QT_API'] = 'pyqt5'. Then I tried to build an executable using cx_freeze with the posted setup.py. It build the exe without errors but when I try to run the exe I get the errormessage: "RuntimeError: No traitsui.toolkits plugin found for toolkit null" – roflcopter122 Oct 19 '18 at 11:48
  • @Jannick: I downgraded the packages you suggested in your thread: mayavi 4.5.0+vtk71, traits 4.6.0, pyface 5.1.0 and traitsui 5.1.0. But when I try to run my script I get this error now: ImportError: No module named 'vtkCommonCorePython' Do you have vtk installed properly? VTK (and build instructions) can be obtained from http://www.vtk.org. I am still using pyqt5. What version of pyqt did you use? – roflcopter122 Oct 19 '18 at 12:12
  • @roflcopter122 I use pyqt4 because there are still some issues of mayavi with pyqt5 as far as I know. The error ImportError: No module named 'vtkCommonCorePython' Do you have vtk installed properly? indicates that the vtk version does not match your mayavi build. Try to uninstall both explicitely with pip uninstall vtk/mayavi and install them from scratch. – Jannick Oct 19 '18 at 13:46
  • Okay I try to reinstall the packages. Is it a big deal to downgrade pyqt? – roflcopter122 Oct 20 '18 at 15:51
  • @roflcopter122 you can have pyqt4 and pyqt5 alongside each other – Jannick Oct 20 '18 at 17:45
  • @Jannick did you also have problems with QtWidgets ? Using PyQt4 I get the error: ModuleNotFoundError: No module named 'PyQt4.QtWidgets' ? After a little bit google I figured out that PyQt4’s QtGui module has been split into PyQt5’s QtGui, QtPrintSupport and QtWidgets modules. Therefor I changed PyQt4.QtWidgets to PyQt4.QtGui. Now I don't get any error when I run my script but the strange thing is that nothing happened... My GUI doesn't display at all... Slowly I am getting very desperate ^^ Maybe you had a similar case ? – roflcopter122 Oct 20 '18 at 18:26
  • When I run the script in spyder after a certain time I get the message from console: Kernel died, restarting... – roflcopter122 Oct 20 '18 at 18:47
  • @roflcopter122 Just a wild guess: Try to change the line where you instantiate QApplication from app = QtGui.QApplication() to app = QtGui.QApplication.instance() – Jannick Oct 20 '18 at 21:17
  • That's how it was before when I used pyqt5... Another question. If I import QApplication like: from PyQt4.QtGui import QApplication. Do I still need to write QtGui.QApplication.instance() ? – roflcopter122 Oct 20 '18 at 21:20
  • @Jannick I am still struggling with getting my script running with pyqt4. I completely reinstall python and all packages from sketch. Now it is working with pyqt without errors. When I change all the pyqt5 imports to pyqt4 and run the script from cmd again nothing happens. When I run the script from spyder I get the error: "ImportError: Importing PyQt4 disabled by IPython, which has already imported an Incompatible QT Binding: pyqt5". So I guess the issue has something to do with the backend? I set it with the line: 'os.environ['ETS_TOOLKIT'] = 'qt4''. – roflcopter122 Oct 21 '18 at 09:55
  • @roflcopter122 Do you have both line os.environ['QT_API'] = 'pyqt' and os.environ['ETS_TOOLKIT'] = 'qt4' ? – Jannick Oct 22 '18 at 07:42
  • @Jannick yes I do have this two lines. – roflcopter122 Oct 22 '18 at 09:16
  • Which version of Python and `cx_Freeze` are you using? – jpeg Oct 22 '18 at 12:40
  • Hi I am using cx_freeze 5.1.1. – roflcopter122 Oct 22 '18 at 14:29
  • People I finally solved the secret!! I just reinstalled pyface (version 5.1) and then it worked. Thank you for all the help!! – roflcopter122 Oct 22 '18 at 20:34
  • Great. Please consider adding an answer with your solution and mark it as accepted so that it becomes more visible to others potentially encountering the same error. – jpeg Oct 23 '18 at 06:37

0 Answers0