35

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?

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Nabeel Ayub
  • 1,060
  • 3
  • 15
  • 35

5 Answers5

46

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

Sushant
  • 3,499
  • 3
  • 17
  • 34
  • Okay, going to check this. – Nabeel Ayub Jul 21 '18 at 12:41
  • In my program when login button is clicked it checks in database and then os.system ('mainwindow.exe') is called which should open the mainwindow but it is not opening while when I exit mainwindow then os.system ('loginform.exe') is called which works perfectly. Is this the right way to call the forms or not? – Nabeel Ayub Jul 21 '18 at 12:56
  • You'll have to debug the behaviour yourself. Your question said you wanted to build into one `exe` which happens with the answer above. Regarding this, it'd make sense to ask a new question as it will change the current question @MUHAMMADNABEELL1F14BSCS0108 – Sushant Jul 21 '18 at 13:17
  • Its done actually it was the problem of DB with Pyinstaller. – Nabeel Ayub Jul 21 '18 at 13:55
  • @NabeelAyub any lucky? – Marcelo Gazzola Jan 30 '21 at 15:12
10

Try this:

pyinstaller --onefile main_app.py
Agile_Eagle
  • 1,710
  • 3
  • 13
  • 32
3

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

Max Feinberg
  • 810
  • 1
  • 6
  • 21
1

Finally i got the answer. check the below command

pyinstaller C:/version_0_1_client_server/scripts/filename.py --paths C:/version_0_1_client_server/  --add-data 'data/config.yaml;data' --add-data 'data/image.png;data'

File Stracture:

Folder : version_0_1_client_server

    sub folder : 
                 data
                 scripts

data folder having png files ane extra files.


i am using this command it will tackcare about all .py files dependenses

0

I think the solution is to edit the .spec file and run pyinstaller on the spec file instead of the individual .py files.

You can find information about adding multiple exes to as single .spec file here: https://pyinstaller.readthedocs.io/en/v3.3.1/spec-files.html#multipackage-bundles

Techniquab
  • 843
  • 7
  • 22