Python Forum

Full Version: Convert py file to exe
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I need help to convert four python files (they are all about the same program) in just one executable file that can be installed in other computers without python. I searched for solutions on the web, but I just found ways to convert one file and not how to do it with more than one. I'm new on it.
how are the 4 files linked to one another? Is there one main file that import the others?
Actually I have a similar problem. I've got a few .py files that I want to convert to exe. The user will run the exe from an Excel macro object (i.e. they click a button in Excel and my code runs). All of the py files are independent, but they all import the same modules (pandas, openpyxl). I use pyinstaller.

I can obviously compile them one by one, but the resulting folder size is large (around 150MB + for each exe, I have three of them and they aren't exactly sophisticated code). The computer that runs the code has a 5400RPM drive so using --onefile has a big performance impact. Is there a way to compile the .py files together, where all the three exe(s) sit in one folder? The idea is to reduce the total folder size.
(Jul-16-2020, 06:28 PM)buran Wrote: [ -> ]how are the 4 files linked to one another? Is there one main file that import the others?

They are functions to be called on the main file, so yes, the main import them.
(Jul-17-2020, 03:43 PM)SmukasPlays Wrote: [ -> ]They are functions to be called on the main file, so yes, the main import them.
Then it's no problem as eg Pyinstaller will find all files that are in import.
Same with 3rd-party packages Pyinstaller will naviagte the whole import tree.
PyInstaller Wrote:The main goal of PyInstaller is to be compatible with 3rd-party packages out-of-the-box.
This means that,with PyInstaller,all the required tricks to make external packages work are already integrated within PyInstaller itself so that there is no user intervention required.
There are many Thread here about Pyinstaller if search,eg a quick demo here.
Someone has made a GUI version for Pyinstaller Auto PY to EXE,i have not tested it.
You must tell pyinstaller to add the files you import in the main file

if you want a directory with all

pyinstaller -D --clean --add-data "/path/file1.py:." --add-data "/path/file2.py:." --distpath /path_to_dist/ '/path/mainFile.py'

for one file

pyinstaller -F --clean --add-data "/path/file1.py:." --add-data "/path/file2.py:." --distpath /path_to_dist/ '/path/mainFile.py'

distpath = path where all will be saved
(Jul-17-2020, 04:24 PM)Axel_Erfurt Wrote: [ -> ]You must tell pyinstaller to add the files you import in the main file
small correction - you may need to tell. Normally pyintsaller will find them, unless there is some complex import scheme

also --add-data option is for additional non-binary data, e.g. data files, not really for adding other python modules.
you may use --hidden-import or specify paths using --paths
(Jul-17-2020, 04:24 PM)Axel_Erfurt Wrote: [ -> ]You must tell pyinstaller to add the files you import in the main file
No don't need this at all for .py files that are in import.
The --add-data is for additional files that not are in the import,like eg a image or a sound file.
(Jul-17-2020, 04:57 PM)snippsat Wrote: [ -> ]like eg a image or a sound file
usually for binary files --add-binary will be used. not sure if it makes difference, though. I think everything goes in datas in the spec file
(Jul-17-2020, 04:07 PM)snippsat Wrote: [ -> ]
(Jul-17-2020, 03:43 PM)SmukasPlays Wrote: [ -> ]They are functions to be called on the main file, so yes, the main import them.
Then it's no problem as eg Pyinstaller will find all files that are in import.

Oh, I was doing something wrong. Now it worked. But have another problem. When I execute any of the functions that are in the other files, they open but the CMD also open. How can I remove the CMD window? I have already tried to use the command "--noconsole" and the extension .pyw. --noconsole worked just for the main file, for the others the CMD is still opening.
Pages: 1 2