Or use PyInstaller as an alternative to py2exe. Here is a good starting point. PyInstaller also lets you create executables for linux and mac...

Here is how one could fairly easily use PyInstaller to solve the issue at hand:

pyinstaller oldlogs.py

From the tool's documentation:

PyInstaller analyzes myscript.py and:

  • Writes myscript.spec in the same folder as the script.
  • Creates a folder build in the same folder as the script if it does not exist.
  • Writes some log files and working files in the build folder.
  • Creates a folder dist in the same folder as the script if it does not exist.
  • Writes the myscript executable folder in the dist folder.

In the dist folder you find the bundled app you distribute to your users.

Answer from zenpoy on Stack Overflow
🌐
Baeldung
baeldung.com › home › files › creating a binary from a python file
Creating a Binary From a Python File | Baeldung on Linux
March 18, 2024 - It’s a straightforward test script written using Python and executed using Python3: $ cat baeldung_python_binary_demo.py #!/usr/bin/python print ("Welcome to Baeldung Article") $ python3 baeldung_python_binary_demo.py Welcome to Baeldung Article · Now, let’s use the PyInstaller to convert this Python script into a binary file: $ pyinstaller --onefile baeldung_python_binary_demo.py 118 INFO: PyInstaller: 6.0.0 118 INFO: Python: 3.10.12 119 INFO: Platform: Linux-6.2.0-33-generic-x86_64-with-glibc2.35 120 INFO: wrote /home/labenv/baeldung_python_binary_demo.spec ...
Discussions

linux - How can I get a binary from a .py file - Unix & Linux Stack Exchange
I need a program to compile python ... I need to make a binary file from my python script. I've already checked a lot of links, but still I haven't found something for Linux. I found py2bin for OS/X, but there are no versions for Linux. ... Nathaniel M. Beaver – Nathaniel M. Beaver · 2018-02-20 13:11:03 +00:00 Commented Feb 20, 2018 at 13:11 · Cython is a popular optimizing static compiler for Python. ... wiki.python.org/moin/Freeze That method will compile executables for *nix ... More on unix.stackexchange.com
🌐 unix.stackexchange.com
February 20, 2018
Need to convert a Python script to an executable version in Linux (RHEL). Is there any "Executable" format in Linux like ".exe" in windows? Is it binary ?
Is there any "executable" filetype in linux (similar to .exe in windows) and can I convert my .py file/files to this format ? Ultimately, I want to run the script as a process/processes, but not as python script, rather something like a regular process. If I apply "which" to any linux command, I can see that they all run from /usr/bin/ or /usr/sbin/ etc. And if I try to open that it shows a lot of unreadable texts, which makes me think they are binary ... More on reddit.com
🌐 r/linuxadmin
8
0
November 20, 2020
Can Python be compiled to binary in any case?
I’m new to python, I’m confused about whether python can be compiled to binary in any case ? I mean no matter how my code is written, as long as it runs correctly, it could be compiled to binary in spec platform? More on discuss.python.org
🌐 discuss.python.org
19
1
December 9, 2022
convert python script file to binary in linux operating system - Stack Overflow
How do i convert python script file to binary executable file in Linux operating system. Ex scriptfile.py: #!/usr/bin/python print "Hello, World" How to covert scriptfile.py to binaray file "scri... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Python.org
discuss.python.org › python help
How to compile the Python code to executable binary file like Linux C and Golang - Python Help - Discussions on Python.org
July 25, 2023 - Hi, how can I compile the python files to an executable binary file like Linux C and Golang in different platforms such as Linux, Mac and Windows?
🌐
LinkedIn
linkedin.com › pulse › create-binary-file-from-your-python-program-srijan-kafle
Create a binary file from your python program
May 9, 2023 - #!/usr/bin/python3 print("#######################################################") print(" __ __ __ __ ") print(" / /_/ /_ ___ ____ ____ ____ / /_ ___ _____/ /_") print(" / __/ __ \/ _ \/ __ \/ __ \/ __ \/ __ \/ _ \/ ___/ __/") print("/ /_/ / / / __/ / / / /_/ / /_/ / /_/ / __/ / / /_ ") print("\__/_/ /_/\___/_/ /_/\____/\____/_.___/\___/_/ \__/ ") print("#######################################################\n\n") print("Hello World!!!") print("This script will be converted to binary file") ... Next, you'll need to install PyInstaller. You can install it using pip: ... Once PyInstaller is installed, navigate to the directory where your Python script is located and run the following command in your terminal: ... The --onefile switch tells PyInstaller to package the script and all its dependencies into a single executable file.
🌐
Medium
medium.com › @adrian.errea.lopez › embedding-your-python-script-into-a-portable-binary-executable-11354ee70db3
Embedding your python script into a portable binary executable | by Adrian Errea Lopez | Medium
February 24, 2023 - This can save tons of time when replicating a product or functionality. ... Finally, you can decompress the tar file in any folder of your new VM, export the LD_LIBRARY_PATH variable as seen before and run the executable as just seen above. Remember that the python folder must be placed at the same level as the binary_exec because we specify that in the CMakeLists.txt.
🌐
Techmonger
techmonger.github.io › 82 › pyinstaller-script-to-binary
Generate Executable Binary From Python Program - Pyinstaller - Tech Monger
$ virtualenv -p python3 venv $ . venv/bin/activate (venv) $ pip install pyinstaller --upgrade ... After successful conversion you will be able to Locate and Execute binary file inside ./dist with the name hello
Find elsewhere
🌐
Dark Artistry
darkartistry.com › home › produce a linux binary from python code
Produce a Linux Binary from Python Code - Dark Artistry
June 18, 2026 - Producing a executable Linux binary from Python code was extremely easy. This tutorial will produce a binary executable from a Python program that contains the code and libraries in a single program. This will make sharing or installing the program on other computers hassle free. The main tool I will be using is uv Astral as it makes everything way easy.
🌐
Quora
quora.com › Can-Python-code-be-compiled-into-a-binary-executable
Can Python code be compiled into a binary executable? - Quora
Answer: No. The compiler takes the human language code and compiles it into machine code, it is the linker that resolves all addresses of the machine code and the load address to create a binary exe file.
🌐
Python.org
discuss.python.org › python help
Can Python be compiled to binary in any case? - Python Help - Discussions on Python.org
December 9, 2022 - I’m new to python, I’m confused about whether python can be compiled to binary in any case ? I mean no matter how my code is written, as long as it runs correctly, it could be compiled to binary in spec platform?
🌐
Medium
medium.com › analytics-vidhya › how-to-create-executable-of-your-python-application-from-linux-windows-mac-bcbcdd4603d4
How to create executable of your Python application for Linux / Windows / Mac | by Ganesh Chandrasekaran | Analytics Vidhya | Medium
October 9, 2020 - PyInstaller library helps you to create an executable (binary) version of your Python script. Step 1 : Make sure python3 development libraries are available (Linux users)
🌐
Stack Overflow
stackoverflow.com › questions › 49042978 › convert-python-script-file-to-binary-in-linux-operating-system
convert python script file to binary in linux operating system - Stack Overflow
How do i convert python script file to binary executable file in Linux operating system. Ex scriptfile.py: #!/usr/bin/python print "Hello, World" How to covert scriptfile.py to binaray file "scri...
🌐
Stack Overflow
stackoverflow.com › questions › 55645822 › how-do-i-convert-python-script-into-linux-standalone-executable-binary-using-cyt
How do I convert python script into Linux standalone executable/binary using Cython? - Stack Overflow
Above I shared my code directory and "main.py" is the file that runs the whole code. Here is the process I followed: Commands to build code for linux 1. cython --embed -o main.c main.py 2. gcc ...
🌐
Hynek
hynek.me › til › python-portable-binaries
TIL: You Can Build Portable Binaries of Python Applications
March 19, 2024 - Then came PyOxidizer. Gregory Szorc has been patiently building a whole toolchain to make Python applications – and Python itself! – portable. Long story short, doc2dash 3.0 is going to have portable binaries for Linux, macOS, and Windows.
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › software › raspberry pi os
Compile python script to binary - Raspberry Pi Forums
Sat Oct 05, 2013 5:13 pm Hi, Yes ... ImportError: No module named setuptools Thanks Step 1: Click on the below link https://github.com/pyinstaller/pyinstaller/releases Step 2: Download PyInstaller-3.3.1.tar.gz and Expand the archive....
🌐
StorageAdmin
storage-admin.com › home › how to convert python scripts to binary files (.exe)
How to Convert Python Scripts To Binary Files (.exe) - StorageAdmin
July 4, 2022 - One thing to note that you have to run the binary file in 64 bit operating system only if you have used a 64 bit operating system to convert .py file to .exe file. Check out our entire posts on python scripting for storage admins. We will use a python module called pyinstaller to convert a .py file to .exe file. Py · Step 1. Open Command Prompt · Step 2. Install pyinstaller module by executing below command
🌐
Quora
quora.com › Is-it-possible-to-write-an-executable-binary-file-using-python-3-file-I-o-Im-tring-to-learn-compiler-linkers-assemblers-etc-perhaps-trying-to-write-machine-code-directly-into-a-file-make-something-clearer
Is it possible to write an executable binary file using python 3 file I/o? I'm tring to learn compiler, linkers, assemblers, etc. perhaps trying to write machine code directly into a file make something clearer. - Quora
Answer (1 of 3): It is certainly possible but I wouldn’t recommend it at first. As a first program try compiling your own language to basic C. If you feel very confident, or as a second project, convert it to assembler instead. Right there you have 99% of the work and you never have to deal wit...
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › programming › python
python to binary file from ubuntu - Raspberry Pi Forums
Python does create .pyc files, which are a sort of binary file, which Python uses to speed up subsequent runs of the program if the source hasn't changed, but they are not portable, can't usually be copied from one system to another and used, are not meant to be copied. ... PyInstaller supports making executables for Windows, Linux, and macOS, but it cannot cross compile.