PyInstaller


Posted:   |  More posts about python deployment notes

Quick look into pyinstaller.

Installation and usage straight forward - https://github.com/k4ml/test-pyinstaller

Single file

Generate single executable script in ./dist:-

pyinstallers --onefile script.py

Extra Paths

If your libraries exists in some non standard path such as the system site-packages you can specify it using the -p option:-

pyinstallers --onefile -p /path/to/mylib script.py

Hidden Import

If your app (or libries you depend on) doing dynamic import, such as using __import__ function, pyinstaller would not be able to detect that in it's static analysis and the module would be missing in the final executable. To help pyinstaller discover these modules, it provide hook mechanism but I failed to get it work. Passing the module name through command line options did work however:-

pyinstallers --onefile -p /path/to/mylib --hidden-import=awscli.converters script.py

For a few hidden import, above is fine but as the number grow, passing it as command line option quickly getting out of hand. The hook mechanism provide utility function that can discover all sub-modules.

Data Files

This is the show stopper when you need to bundle third party libraries not under your control. If the library need to access data file, it has to be aware that it running under pyinstaller and make some adjustment to the file path.

Comments powered by Disqus

About me

Web developer in Malaysia. Currently work at MARIMORE Inc building internet services using Python and Django web framework.

ImportError is an error message emitted by Python when it failed to load certain module as requested by programmer. It's a very common error when someone new to the language trying it out. This website on the same theme, will try provide help for newcomers on any technologies to overcome their first hurdle.

Try most of the examples you may find here on Digital Ocean cloud service. They provide excellent VPS at a very cheaper price. Using this referral link you'll get USD10 credits upon sign up. That's enough to run single VPS with 1GB RAM for a month.

Others

I can also be found at the following sites:-

  • http://k4ml.blogspot.com/
  • http://k4ml.github.io/
  • http://metak4ml.blogspot.com/
  • http://www.mydev.my/
  • http://github.com/k4ml/

Disclaimers

The postings on this site are my own and don't necessarily represent my employer's positions, strategies or opinions.

Share