Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build multiple .py files into a single executable file using pyinstaller?

I have made a small PyQt application containing 5-6 .py files. Now I want to build and compile them into a single main file, meaning it has to operate from one main window exe.

My .py files are connected with each other successfully. I have used pyinstaller to make the executable file, but the problem is I built each .py file into its own .exe file. But I want to make a single .exe file through which all the .py files can be used.

How to build all .py files into a single .exe file?

like image 520
Nabeel Ayub Avatar asked Jul 21 '18 11:07

Nabeel Ayub


People also ask

Can PyInstaller cross compile?

PyInstaller supports making executables for Windows, Linux, and macOS, but it cannot cross compile. Therefore, you cannot make an executable targeting one Operating System from another Operating System. So, to distribute executables for multiple types of OS, you'll need a build machine for each supported OS.

Does PyInstaller compile Python?

However, PyInstaller bundles compiled Python scripts ( . pyc files). These could in principle be decompiled to reveal the logic of your code. If you want to hide your source code more thoroughly, one possible option is to compile some of your modules with Cython.


3 Answers

Suppose you had a file called create.py like

def square (num)
    return num ** 2 

Another file in the same directory called input.py

from . import create
def take_input():
    x = input("Enter Input")
    return create.square(x)

And finally your main.py

from . import input
if __name__ == '__main__':
    ip = input.take_input()

You will call the command -

pyinstaller --onefile main.py

And pyinstaller will import all the dependencies of all the files itself

like image 89
Sushant Avatar answered Oct 22 '22 19:10

Sushant


Try this:

pyinstaller --onefile main_app.py
like image 8
Agile_Eagle Avatar answered Oct 22 '22 19:10

Agile_Eagle


Use the Command pyinstaller --onefile yourprogramname.py. Pyinstaller will Automatically import and Compile the Dependency Files.

like image 2
Sharath Chandra Avatar answered Oct 22 '22 19:10

Sharath Chandra