Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Convert py file to exe
#1
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.
Reply
#2
how are the 4 files linked to one another? Is there one main file that import the others?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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.
Reply
#4
(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.
Reply
#5
(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.
Reply
#6
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
Reply
#7
(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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#8
(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.
Reply
#9
(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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#10
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question [SOLVED] Correct way to convert file from cp-1252 to utf-8? Winfried 8 902 Feb-29-2024, 12:30 AM
Last Post: Winfried
  Convert File to Data URL michaelnicol 3 1,179 Jul-08-2023, 11:35 AM
Last Post: DeaD_EyE
  Python Script to convert Json to CSV file chvsnarayana 8 2,542 Apr-26-2023, 10:31 PM
Last Post: DeaD_EyE
  Convert Excel file into csv with Pipe symbol.. mg24 4 1,340 Oct-18-2022, 02:59 PM
Last Post: Larz60+
  Need Help: Convert .pcl file to .pdf file ManuRaval 6 2,562 Sep-13-2022, 01:31 PM
Last Post: ManuRaval
  Convert legacy print file to XLSX file davidm 1 1,817 Oct-17-2021, 05:08 AM
Last Post: davidm
  Yahoo_fin, Pandas: how to convert data table structure in csv file detlefschmitt 14 7,805 Feb-15-2021, 12:58 PM
Last Post: detlefschmitt
  [split] How to convert the CSV text file into a txt file Pinto94 5 3,376 Dec-23-2020, 08:04 AM
Last Post: ndc85430
  CPC File Format (Cartesian Perceptual Compression) - Can Python Convert / Handle Them PSKrieger 2 2,485 Nov-11-2020, 02:57 PM
Last Post: PSKrieger
  Convert file of hex strings to binary file medatib531 4 13,772 Oct-09-2020, 05:42 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020