1

My Python 2.7 application uses matplotlib, enthought (mayavi, traits), wxpython libraries. I need to package it into an executable on Windows, which, after some research and experimenting seems like a not straightforward task.

I have so far experimented with PyInstaller and bbfreeze. In both of them I specify hidden imports/includes (which I could gather fromrandom information on the web) to import the Enthought packeges. Both manage to create an executable (for bbfreeze I excluded the matplotlib part of my application so far), but when I run it, both return the same error:

Traceback (most recent call last):
File "<string>", line 6, in <module>
File "__main__.py", line 128, in <module>
File "__main__test__.py", line 23, in <module>
File "traitsui/api.py", line 36, in <module>
File "traitsui/editors/__init__.py", line 23, in <module>
File "traitsui/editors/api.py", line 49, in <module>
File "traitsui/editors/table_editor.py", line 37, in <module>
File "traitsui/table_filter.py", line 35, in <module>
File "traitsui/menu.py", line 128, in <module>
File "pyface/toolkit.py", line 98, in __init__
NotImplementedError: the wx pyface backend doesn't implement MenuManager

Any ideas what should I do? Alternatively has anyone had experience with creating such an executable and can recommend a tool or method ? So far I have seen only this tutorial but it uses py2exe and apparently requires downloading the whole ETS - if nothing else gonna give it a try...

shiftyscales
  • 441
  • 4
  • 20
  • I'm at the same exact point (asked as similar question myself with no answer, also). Please keep me in the loop if you ever figure out a solution! – brettb Apr 21 '16 at 20:52
  • hi, I did fiugure it out in the end, see my answer below – shiftyscales Apr 22 '16 at 14:36
  • Thanks @Shifty Scales. I'll try this out. I was hoping to use PyInstaller because that is what we use for majority of our projects, but if cx_freeze works, then it will have to do! – brettb Apr 22 '16 at 15:21

1 Answers1

0

Here is the solution which worked for me.

I have tried to use bbfreeze, PyInstaller , py2exe and cx_Freeze. In the end I decided to go with cx_Freeze as it is apparently popular with people who are packaging the applications with enthought classes.

With cx_Freeze I got the similar error message as above. The problem is that it saves the necessary modules in "library.zip" file, which is something that enthought classes including mayavi have problem with. Fortunately cx_Freeze allows specifying "create_shared_zip": False option, which then makes it so that source files are directly copied into the build directory as they are, instead of in a zip file.

Additionally, I have found that some Enthought files and folders have to be manually included in include_files (same goes for scipy, source: here). After this it worked. I add my setup file code below, hope it helps.

import sys
import os
from cx_Freeze import setup, Executable
import scipy

scipy_path = os.path.dirname(scipy.__file__) #use this if you are also using scipy in your application

build_exe_options = {"packages": ["pyface.ui.wx", "tvtk.vtk_module", "tvtk.pyface.ui.wx", "matplotlib.backends.backend_tkagg"],
                     "excludes": ['numarray', 'IPython'],
                     "include_files": [("C:\\Python27\\Lib\\site-packages\\tvtk\\pyface\\images\\", "tvtk\\pyface\\images"),
                                       ("C:\\Python27\\Lib\\site-packages\\pyface\\images\\", "pyface\\images"),
                                       ("C:\\Python27\\Lib\\site-packages\\tvtk\\plugins\\scene\\preferences.ini", "tvtk\\plugins\\scene\\preferences.ini"),
                                       ("C:\\Python27\\Lib\\site-packages\\tvtk\\tvtk_classes.zip", "tvtk\\tvtk_classes.zip"),
                                       ("C:\\Python27\\Lib\\site-packages\\mayavi\\core\\lut\\pylab_luts.pkl","mayavi\\core\\lut\\pylab_luts.pkl"),
                                       ("C:\\Python27\\Lib\\site-packages\\mayavi\\preferences\\preferences.ini","mayavi\\preferences\\preferences.ini"),
                                       ("C:\\Python27\\Lib\\site-packages\\numpy\\core\\libifcoremd.dll","numpy\\core\\libifcoremd.dll"),
                                       ("C:\\Python27\\Lib\\site-packages\\numpy\\core\\libmmd.dll","numpy\\core\\libmmd.dll"),
                                       (str(scipy_path), "scipy") #for scipy
                                       ]                       
                     ,"create_shared_zip": False #to avoid creating library.zip
                     }

executables = [
    Executable('myfile.py', targetName="myfile.exe", base=None)
]

setup(name='myfile',
      version='1.0',
      description='myfile',
      options = {"build_exe": build_exe_options},
      executables=executables
      ) 

Configuration:

python 2.7
altgraph==0.9
apptools==4.3.0
bbfreeze==1.1.3
bbfreeze-loader==1.1.0
configobj==5.0.6
cx-Freeze==4.3.3
Cython==0.23.4
matplotlib==1.4.3
mayavi==4.4.3
MySQL-python==1.2.5
natgrid==0.2.1
numpy==1.10.0b1
opencv-python==2.4.12
pandas==0.16.2
pefile==1.2.10.post114
Pillow==3.1.1
plyfile==0.4
psutil==4.1.0
pyface==5.0.0
Pygments==2.0.2
pygobject==2.28.6
pygtk==2.22.0
PyInstaller==3.1
pyparsing==2.0.3
pypiwin32==219
PySide==1.2.2
python-dateutil==2.4.2
pytz==2015.4
scipy==0.16.0
six==1.9.0
subprocess32==3.2.7
traits==4.5.0
traitsui==5.0.0
transforms3d==0.2.1
VTK==6.2.0
Community
  • 1
  • 1
shiftyscales
  • 441
  • 4
  • 20
  • hmmm this seems to have gotten me VERY close, but not quite there. The frozen executable seems to be looking for the tvtk_classes.zip in myfile.zip (or library.zip, if I do create_shared_zip=True). The tvtk_classes.zip file *is* getting packaged, but it is in \build\exe.win-amd64-2.7\tvtk. Did you not run into this issue? – brettb Apr 22 '16 at 19:16
  • I tried to use "zip_includes" as mentioned here: http://stackoverflow.com/questions/10606932/cx-freeze-how-do-i-add-package-files-into-library-zip -- it looks like tvtk/tvtk_classes.zip is making it inside library.zip now, but it still isn't finding it at runtime from the exe! – brettb Apr 22 '16 at 19:55
  • In my case it was looking in tvtk folder, which is why I copy it there. Could you post the error message ? – shiftyscales Apr 23 '16 at 07:32
  • Sure -- here's the error I'm getting (with just username and project name redacted): http://i.imgur.com/RRWmFYm.png – brettb Apr 26 '16 at 13:19
  • hmm not sure what to do if it is still looking lin the zip file after specifying not to create it... – shiftyscales Apr 26 '16 at 14:17
  • Apologies -- the above screenshot was with "create_shared_zip" set to True. If I set it to False, then I get the exact same error message, but instead of looking in library.zip it looks in .zip. Thanks for trying! – brettb Apr 26 '16 at 14:21
  • try additionally `appendScriptToExe = True` - this will make it so that .zip is not created and the scripts are stored in the executable file, as these classes have trouble with zip files it might help - https://sourceforge.net/p/cx-freeze/mailman/message/23971853/ – shiftyscales Apr 26 '16 at 14:40
  • That appears to have fixed the issue of it looking within the .zip, but I'm still getting the same error: `ImportError: TVTK not built properly. Unable to find either a directory: C:\...\tvtk\tvtk_classes or a file: C:\...\tvtk\tvtk_classes.zip with the TVTK classes.` Though, the tvtk_classes.zip definitely does exist... maybe it is an issue with my tvtk installation. – brettb Apr 26 '16 at 14:49
  • maybe, perhaps try reinstalling the packages.. not sure what else to suggest, good luck! – shiftyscales Apr 26 '16 at 15:00
  • 1
    Figured it out -- it was fickle and the solution is too long to post in a comment here. In the end, it was making sure that modules and submodules were in the *same* place (either both in zip/exe/directory), if that makes sense. I had to do this on a package-by-package basis. One big thing that helped: I excluded mayavi, and then pulled over the entire mayavi directory from site-packages through include_files (same for tvtk). – brettb Apr 27 '16 at 12:36
  • Hi, does the "settings" button on mayavi panel work in your packaged version ? – shiftyscales May 19 '16 at 11:29
  • nope... never checked that. oops! I don't really care about it, though, so may just disable it. – brettb May 19 '16 at 21:28
  • Disable as in remove from mayavi toolbar? If you know a way of doing this please let me know :) – shiftyscales May 20 '16 at 16:33
  • I haven't gone into it yet, but there is a way to do it in Matplotlib, so I imagine there is probably a (convoluted) way to do it in mayavi? – brettb May 20 '16 at 17:18