Bbfreeze

0 views
Skip to first unread message

Jenifer Griffard

unread,
Aug 4, 2024, 10:56:40 PM8/4/24
to globlamansi
pathnamesin tracebacks are replaced with relative pathnames(i.e. if you import package foo.bar from /home/jdoe/pylib/tracebacks generated from functions in foo.bar will not show yourlocal path /home/jdoe/pylib/foo/bar.py. They will instead showfoo/bar.py)

documentation is a bit sparsebbfreeze - command line toolbbfreeze provides a command line utility called bbfreeze, whichfreezes all python scripts given on the command line into thedirectory dist, which then contains for each script an executable andall dependencies needed by those executables.


use_compression: flag whether to use compression inside the createdzipfile (default True).include_py: flag whether to create the included python interpreterpy (default True)addScript(path, gui_only=False): register a python script forfreezing. path must be the path to a python script.The freezer will scan the file for dependencies and will create anexecutable with the same name in distdir. The gui_only flag onlyhas a meaning on windows: If set, the executable created for thisscript will not open a console window.RecipesRecipes provide a way to control the freezing process. Have a look atbbfreeze/recipes.py if you need to implement your own. Note that theAPI might change.


bbfreeze contains a modified copy of getpath.c from the pythondistribution, which is distributed under the python softwarefoundation license version 2 and copyrighted by the python softwarefoundation.


The origin of this software must not be misrepresented; you must notclaim that you wrote the original software. If you use this softwarein a product, an acknowledgment in the product documentation would beappreciated but is not required.Altered source versions must be plainly marked as such, and must not bemisrepresented as being the original software.This notice may not be removed or altered from any sourcedistribution. Project details Verified details These details have been verified by PyPI Maintainers schmir Unverified details These details have not been verified by PyPI Project links Homepage Meta License: zlib/libpng License (zlib/libpng license)


The bbfreeze package also allows us to create binaries, but only on Linux and Windows. When you create a binary on Linux, the result will only run on machines that have the same hardware architecture and version of libc, which limits its usefulness on Linux. It should also be noted that bbfreeze only works with Python versions 2.4 - 2.7. You can use easy_install or pip to install the bbfreeze package onto your system. The bbfreeze package includes egg support, so it can include egg dependencies in your binary, unlike py2exe. You can also freeze multiple scripts at once, include the Python interpreter and more.


You will note that when you run the executable, it creates a config file named sampleconfig2.ini. You may see a warning about the pywin32 package not being installed. You can ignore the warning or download and install pywin32.


If you run this, you should end up with a dist folder with about 19 files, but a slightly different size of 19.6 MB. Notice that we added a second argument to the addScript method: gui_only=True. This makes that annoying console go away. We also set compression to zero (no compression) and include the Python interpreter. Turning on compression only reduced the result back down to 17.2 MB though.


Now you should know the basics of using bbfreeze to create binaries from your programs. I noticed that when I ran bbfreeze on my machine, it was considerably slower in producing the wxPython executable compared with py2exe. This is one of those things that you will have to experiment with when you are determining which tool to use to create your binaries.


Last November we switched to Python as the principallanguage for all new software development projects at work, ditching MicrosoftVisual C++ and PHP in the process. Last Friday we released our first Pythonapplication to our customers for both Windows and Linux users.


Although we make good use of Open Source software development tools andmethodologies the application we have just written is propritary and thesource can not be released publicly. We needed to compile, or freeze, thePython script in order to create a standalone executable. Tools that do thishave been around for sometime, however our application makes use of Win32Extensions for Python and WMI on Windows, DBUS/HAL on Linux, wxPythonon both, and a number of other modules. This is quite a big ask for the Pythonscript compilers and initially the only tool which could build this lotsuccessfully was py2exe. Sadly that only solves partof the problem since it is a Windows only tool.


Then we found bbfreeze, whichsupports both Windows and Linux with Mac OS X support being activelydeveloped. bbfreeze has a simple build API and we were soon using it to buildstand alone executables for both Windows and Linux. Everything is peachy, allwe needed was as means to install our application.


We only need a tarball for Linux since we manage all kiosk installations, butour customer can install the Windows version. Enter InnoSetup.InnoSetup is a free installer for Windows programs and installer can even becreated from the command line, perfect for integration with our Jenkins buildservers.


Frozen binaries are a form of distribution for Python applications. They meticulously bundle the Python interpreter, your application's codebase, and all essential libraries and resources into a single, self-contained executable file.


The undeniable advantage of frozen binaries lies in their ability to empower your application to "just work" on any machine, eliminating the need for pre-installed Python. This becomes particularly valuable for end-user applications where you cannot guarantee the user possesses the correct Python version.


However, it's crucial to acknowledge the potential drawbacks. Frozen binaries can cause a significant increase in your application's size due to the inclusion of the Python interpreter and all dependencies. Additionally, the responsibility of updating your application to address security vulnerabilities in Python falls upon you.


Install a Freezing Tool: The initial step involves installing a freezing tool, such as py2exe, py2app, cx_Freeze, bbfreeze, or PyInstaller. The tool selection hinges on your requirements and target platform.


Craft a Setup Script: Next, create a setup script specific to the chosen freezing tool. This script instructs the tool on which scripts to incorporate into the binary, along with any additional options.


Automate Testing with CI/CD Tools: Open-source projects can benefit from cloud-based CI/CD services to automate testing. These tools can automatically build and test your application on multiple platforms upon codebase modifications.


Packaging Your Code: This method, often used for distributing libraries or tools to other developers, leverages Python's standard distribution tools like setuptools and distutils. These tools enable the creation of source distributions (.tar.gz files) and wheel distributions (.whl files).


Crafting a Linux Distro Package: On Linux systems, you can create a Linux distribution package (e.g., .deb for Debian/Ubuntu or .rpm Red Hat/SuSE). This empowers users to install your application using their system's package manager.


Harnessing Package Managers: Python-specific package managers like pip and conda offer a streamlined approach to code distribution. Users can leverage these tools to install your application and its dependencies with a single command.


Embracing Containerization: Tools like Docker permit you to package your application and all its dependencies into a container. This container can then be executed on any system equipped with Docker.


Cloud-Based Services: Platforms like AWS Lambda and Google Cloud Functions allow you to upload your Python code and execute it in the cloud, eliminating the need for any user-side installations.


Frozen binaries provide a remarkably convenient avenue for distributing Python applications to users, alleviating the requirement for Python or dependency installations. While they do possess limitations, such as increased file size, the benefits often outweigh the drawbacks for many applications.

3a8082e126
Reply all
Reply to author
Forward
0 new messages