How to convert a Python file to an ELF file, and how to execute the generated ELF file with/without using the terminal in Linux?
Prathima Bommannagari
Posted on November 25, 2022
What is an ELF file?
An ELF(Executable and Linkable Format) file is an executable standard file format for the Linux and Unix platforms.
The ELF file format is typically used by binary executables in Linux. These serve as Linux's equivalent to Windows' PE (Portable Executable) format, which uses the EXE file extension.
In addition to the executable code, executable files also include data such as static and dynamic data, linker information, and library imports.
How to convert a Python file to an ELF file?
To generate an ELF file from a python file, we can use pyinstaller.
Install pyinstaller using the below command:
If you are using a python version that's older than python3, replace pip3 with pip in the above command.Create a .py file or go to the path where your existing python file resides.
Run the below command to convert the python file to an executable:
Pyinstaller creates a dist(distribution) directory, that contains the main executable(ELF) and the dynamic libraries bundled in an executable file.
How to run the executable file in Linux?
Using the terminal:
- Open the terminal.
- Go to the path where the ELF file is located and execute the ELF file by placing ./ before the elf filename as below:
Without using the terminal:
- Open the File explorer and go to the path where the ELF is located.
- Right-click on the executable file, go to Properties--> Permissions tab--> check the box 'Allow executing file as program' --> Close the properties window. 3. Run the executable file by just double-clicking on it (similar to running an exe file on Windows).
Posted on November 25, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.