2015年5月12日 星期二

cxfreeze Python program (Linux) - Wrapping the Python Program to Single Executable

I would like to note down here because Googling results frustrating with

  • Large amount of Windows environment Python application wrapping
  • Misleading and lack of example of cxfreeze API

But thanks for Stackoverflow, I finally get the solution despite various failure on different problems during the wrapping of my wxPython application.


Here is my situation
    I have written a wxpython program, and the program consist of not only .py files but with images and xml files, I want to 

  1. Wrap all these stuffs to one executable program in Ubuntu
  2. Deploy this program with deb installer

Solutions
  1. Download and install cxfreeze
  2. Please let me know but I cannot find relative commands on how to include external files, therefore I use the officially provided py script
    http://cx-freeze.readthedocs.org/en/latest/script.html
  3. Follow the below official guide and write the setup script to build the program
    http://cx-freeze.readthedocs.org/en/latest/distutils.html
  4. Run python setup.py build and your program will be built
  5. Follow the file structure to build the deb

  • mpstoolbox is the app name, name your own one
  • DEBIAN/control, DEBIAN/postinst is files to configure the deb package
  • usr/bin/..., this is the installed path, you should make your own path, all the files installed will follow this path structure
  • Finally, cd back to the folder (your app name), use dpkg -b yourAppName
  • A deb package will be generated
  • Use dpkg -i to install

Here comes the MOST important part, my problem

    It seems simple to follow the above to build the program, but indeed it doesn't, the guide does not teach you clearly on how to include the required modules to let you bring your program to other Linux machine to run, you need to follow the followings


  • binpathincludes parameter is important, please include all system library like /usr/lib, /usr/local/lib, or you may encounter this error libwx_gtk2u import error, ImportError: libwx_gtk2u_adv-2.8 etc. This is deal to the missing of wxPython library, you therefore need to include all required system library when building the app
  • About the setup.py, the api is not very clear in cxfreeze, follow stackoverflow's guide, thanks to the bro there, he also suffered from the lack of clearance of the api
    http://stackoverflow.com/questions/15486292/cx-freeze-doesnt-find-all-dependencies

    One thing here to pay attention to, the "include_files" attribute should be a list of tuples instead of single name only!! Your external files and other required images should also put it here.

沒有留言:

張貼留言