Build Multiple .py files into a single executable file using pyinstaller

回眸只為那壹抹淺笑 提交于 2020-05-25 04:35:06

问题


I have made a small pyqt application of 5 and 6 .py files.Now I want to build them and compiled them in a single main file.Mean I have to operate them from one main window exe. My .py files are connected with each other successfully.I have used pyinstaller to make the executable file, the problem is I have build each .py file into its own exe file.But I want to make a single exe file through which whole.py files operate.How to build all .py files into a single exe file.I have searched a lot but unable to resolve my issue.


回答1:


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




回答2:


Try this:

pyinstaller --onefile main_app.py



回答3:


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



来源:https://stackoverflow.com/questions/51455765/build-multiple-py-files-into-a-single-executable-file-using-pyinstaller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!