We have created many interesting projects and programs in Python. Perhaps the time will come when we create something very interesting and we want to share it. Typically, to share our Python program, the recipient will need to have the same version of Python installed, as well as all the modules used. Well, that can be quite tedious to demand. The interest in converting to .exe is high enough for distribution and there are several options. In Python 2.7 Py2exe — great choice, and for Python 3, cx_freeze works pretty well.
CX_Freeze | .py to .exe
cx_Freeze is a set of freeze scripts and modules Python scripts to executables, in much the same way as do py2exe and py2app . Unlike these two tools, cx_Freeze is cross-platform and should work on any platform that Python itself runs on. It supports Python 2.7 or higher (including Python 3).
First we need to download cx_Freeze: download from here or install it using pip:
Once we have cx_freeze, we`re ready to start. We`ll parse python.engineering with regex and urllib.
Output: we added a 14 second sleep mode at the end so that we can run the executable and see the output before closing it. So let`s save this file as “reandurllib.py”.
Now we create a second file called “setup.py”
So, here we are importing from the installation and the executable cx_Freeze, then call the configuration function adding 4 parameters.
Then we open cmd.exe, or bash, or any other shell, go to the directory that contains the setup.py file and the conversion script and run:
python setup.py build
Now we are given a directory for assembly. Inside it we find another directory, and inside it — our executable! If everything went well, it should parse the search results basic with CX_Freeze
This article courtesy of Amartya Ranjan Saikia . If you are as Python.Engineering and would like to contribute, you can also write an article using contribute.python.engineering or by posting an article contribute @ python.engineering. See my article appearing on the Python.Engineering homepage and help other geeks.
Please post comments if you find anything wrong or if you`d like to share more information on the topic discussed above.