0

I made a simple script, turned it into an exe but the final output using auto py to exe with one directory mode was 170 mb, with one file mode it was 64 mb. Thats insane, anyway I can only copy the parts of libraries that my script needs?

EDIT: My script is simple, this is it The libraries are tkinter, keyboard, pyautogui, pywinauto and time.

That Guy
  • 55
  • 1
  • 6
  • Check this [Python – Import from parent directory](https://www.geeksforgeeks.org/python-import-from-parent-directory/) – Mahdi Abadinia Mar 25 '22 at 03:54
  • There's too much information missing from your post. The python interpreter is usually < 10mb, but what libraries are you importing? Some libraries require a lot of space. What other things is your script doing that might balloon it out? Also, why are you trying to create an exe? Do you need specific version of python and libraries that you cannot install on the target system(s)? – Gabe Mar 25 '22 at 04:22
  • @Gabe Yep sorry about that, fixed – That Guy Mar 25 '22 at 07:25
  • https://stackoverflow.com/questions/3528763/py2exe-reduce-size-of-the-library-archive https://stackoverflow.com/questions/9602691/reducing-the-size-of-executable-from-py2exe https://stackoverflow.com/questions/1617868/how-to-reduce-size-of-exe-using-py2exe https://stackoverflow.com/questions/45273039/creating-executable-from-python-script-while-acquiring-small-output-size – DavidW Mar 25 '22 at 08:20

2 Answers2

2

You could create a virtual environment where you can install your required modules and then create the exe file in that environment itself. The python base library would be there anyway. Check out : How to include only needed modules in pyinstaller?

francisb
  • 61
  • 6
0

Use pyinstaller to convert python files to exe.

Installation: pip install pyinstaller

Convert (in Terminal): pyinstaller --onefile "path_to_file.py"

This would create a "dist" folder in the directory you ran the code in and it would contain the ".exe" file of the python file, this only installs the modules used in the program.

But unfortunately, Size of exe Files are usually big due to the modules used, and cannot be helped (in my opinion)

KillerRebooted
  • 470
  • 1
  • 12