Thomas Lecocq @ the Royal Observatory of Belgium

Menu

Pack an Enthought Traits app inside a .exe using py2exe (Canopy Edit)

10 months ago, I published the updated version of my tutorial to pack an Enthought TraitsUI based application inside an .exe Windows Executable file, using a standard Python 2.7 install and the Enthought Tool Suite 4.0 (ETS4.0). In April 2013, Enthought published their latest distribution called “Canopy”. This distribution marks a clear change in the way Python is installed, providing elaborate, and complicated, virtual environments (User – System – App). When an user installs a package, it gets stored in his User\Lib\site-packages\ folder, while if he uses the module out of the Canopy Box, it’s stored in the Canopy default folder, somewhere like App\appdata\canopy-1.0.1.1189.win-x86\lib\site-packages\…

All in all, and because I need to compile my Seismic Data Processing (waveform analysis application), I have to update the py2exe procedure to match those changes.

To Start, I assume you have read a little about the Canopy Structure and its inner workings.

The way the extra packages data_files were included before doesn’t work, because there is not a single site-packages folder to hold the required modules. So, the logic needs to be replaced using a slightly more clever approach, by defining the paths where modules could be, in the order of the Canopy logic,

Traceback (most recent call last):
File "example.py", line 10, in <module>
File "traits\has_traits.pyc", line 2561, in configure_traits
File "traitsui\api.pyc", line 35, in <module>
File "traitsui\editors\__init__.pyc", line 22, in <module>
File "traitsui\editors\api.pyc", line 6, in <module>
File "traitsui\editors\array_editor.pyc", line 27, in <module>
File "numpy\__init__.pyc", line 143, in <module>
File "numpy\add_newdocs.pyc", line 9, in <module>
A `flatiter` iterator is returned by ``x.flat`` for any array `x`.
File "numpy\lib\__init__.pyc", line 13, in <module>
File "numpy\lib\polynomial.pyc", line 17, in <module>
Functions to operate on polynomials.
File "numpy\linalg\__init__.pyc", line 48, in <module>
File "numpy\linalg\linalg.pyc", line 23, in <module>
t
ImportError: DLL load failed: The specified module could not be found.

The numpy.linalg module only contains one precompiled shared library (lapack_lite.pyd), so I checked its dependencies using Dependency Walker, and noticed the missing libraries:

The missing libraries are:

MK2_INTEL_THREAD.DLL

MSVCR90.DLL

GPSVC.DLL

IESHIMS.DLL

The first, MK2_INTEL_THREAD.DLL is a shared library present in the App directory of Canopy (C:\Users\thomas\AppData\Local\Enthought\Canopy32\App\appdata\canopy-1.0.1.1189.win-x86\Scripts in my case). I use Canopy 32bits version, which comes with Numpy built against MKL. I assume all MK2*.dll should be available to the compiled code, so I’ll copy them to the numpy/linalg folder. The second is present in the matplotlib.backends module, same, I’ll copy it to the folder. The two last appear on the image above with a small hourglass, meaning they are delayed libraries (and somehow we can, I assume from the result below, not care about them). To hack this MKL problem, we add the files to the data_files array of our setup.py:

Now, one could argue that building an application on Canopy is not clever, because this or that. The fact is that Canopy is my work environment, and most of the improvements that I bring to the seismic software come from this everyday work. Building the application with state of the art and regularly updated modules and packages is a necessary regular exercise not to loose contact with the advances, plusI don’t have time/envy to play/hack/any with other Python distributions.

Let me know if you succeed building your applications with this tutorial, and if you have ideas to improve it !

Meta

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPT

Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.

Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.

Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.