[GH-ISSUE #195] "Only needed packages" option needed. #176

Closed
opened 2026-02-26 12:20:43 +03:00 by kerem · 3 comments
Owner

Originally created by @Drill-N-Bass on GitHub (Sep 4, 2021).
Original GitHub issue: https://github.com/brentvollebregt/auto-py-to-exe/issues/195

Hello,

I have a problem related to this faq.
Quote:

"The Output Executable is Huge
Sometimes pyinstaller tries to be smart and will add packages it sees in your environment even if you are not using them in the project being packaged. This can lead to output executables being tens to hundreds of megabytes in size.

To get around this, the easiest way would be to:

Create a new/clean virtual environment
Install auto-py-to-exe into it
Install the required modules for your project
Use the auto-py-to-exe in this virtual environment to package your script
Doing this will mean pyinstaller doesn't see the packages you don't need bundled which can lead to smaller packages."

My problem is: when I use another console to avoid additional packages to be installed, then there are some packages that are missing. No matter that I've installed them by this "new console".

So I can either fail with compression in the new console, or compress my file to exe in Anaconda console, but my folder with this compressed program weight - after compression - to almost 1 GB. It should have somethin between 20-70 MB!

Is it possible to add new feature to your program, that would detect any instances of import command in code and include only packages related to this import command? After the command import string, there is always the name of particular package auto-py-to-exe could use. That would solve the whole issue.
Or, maybe, before compressing, in this GUI window (auto-py-to-exe) create some sort of string searcher that will search for all instances of "import" strings in code/codes, then thanks to that, find all packages, list them in GUI and ask the user which he/she want to add to output.

This task seems to be doable.

Paul.

Originally created by @Drill-N-Bass on GitHub (Sep 4, 2021). Original GitHub issue: https://github.com/brentvollebregt/auto-py-to-exe/issues/195 Hello, I have a problem [related to this faq](https://nitratine.net/blog/post/issues-when-using-auto-py-to-exe/?utm_source=auto_py_to_exe&utm_medium=application_link&utm_campaign=auto_py_to_exe_help&utm_content=top#the-output-executable-is-huge). Quote: >"The Output Executable is Huge Sometimes pyinstaller tries to be smart and will add packages it sees in your environment even if you are not using them in the project being packaged. This can lead to output executables being tens to hundreds of megabytes in size. >To get around this, the easiest way would be to: >Create a new/clean virtual environment Install auto-py-to-exe into it Install the required modules for your project Use the auto-py-to-exe in this virtual environment to package your script Doing this will mean pyinstaller doesn't see the packages you don't need bundled which can lead to smaller packages." My problem is: when I use another console to avoid additional packages to be installed, then there are some packages that are missing. No matter that I've installed them by this "new console". So I can either fail with compression in the new console, or compress my file to exe in Anaconda console, but my folder with this compressed program weight - after compression - to almost 1 GB. It should have somethin between 20-70 MB! Is it possible to add new feature to your program, that would detect any instances of `import` command in code and include only packages related to this import command? After the command `import` string, there is always the name of particular package `auto-py-to-exe` could use. That would solve the whole issue. Or, maybe, before compressing, in this GUI window (auto-py-to-exe) create some sort of string searcher that will search for all instances of "import" strings in code/codes, then thanks to that, find all packages, list them in GUI and ask the user which he/she want to add to output. This task seems to be doable. Paul.
kerem 2026-02-26 12:20:43 +03:00
  • closed this issue
  • added the
    Stale
    label
Author
Owner

@brentvollebregt commented on GitHub (Sep 4, 2021):

Using the new/clean virtual environment, did you run your program to check if it still works in the new environment? With you saying "then there are some packages that are missing", I have a feeling you may have not. I highly recommend testing your application out in the new virtual environment as if it does not work here, it will definitely not worked packaged.

Also another thing to look out for is to make sure you are using the auto-py-to-exe from this new virtual environment and not the auto-py-to-exe from the previous environment that lead to large executable sizes.

In terms of your request for package detection, this is handled by PyInstaller so you will need to raise concerns with that repository. However, your request:

detect any instances of import command in code and include only packages related to this import command

is what PyInstaller does already - there are just some extra hooks that include other imports as libraries do not always use import statements. If PyInstaller did not do this extra searching, most imports or larger libraries would probably lead to broken executables.

In terms of

create some sort of string searcher that will search for all instances of "import" strings in code/codes

PyInstaller offers a build-time dependency graph, however they do note that this will show a significant amount of standard modules which can make the output huge. Looking at the output, you could then use the --exclude-module flag to ignore packages you do not want to be added. To get this output, I would recommend using PyInstaller directly using the generated command in auto-py-to-exe.

<!-- gh-comment-id:913042518 --> @brentvollebregt commented on GitHub (Sep 4, 2021): Using the new/clean virtual environment, did you run your program to check if it still works in the new environment? With you saying "then there are some packages that are missing", I have a feeling you may have not. I highly recommend testing your application out in the new virtual environment as if it does not work here, it will definitely not worked packaged. Also another thing to look out for is to make sure you are using the auto-py-to-exe from this new virtual environment and not the auto-py-to-exe from the previous environment that lead to large executable sizes. In terms of your request for package detection, this is handled by [PyInstaller](https://github.com/pyinstaller/pyinstaller) so you will need to raise concerns with that repository. However, your request: > detect any instances of import command in code and include only packages related to this import command is what PyInstaller does already - there are just some extra hooks that include other imports as libraries do not always use import statements. If PyInstaller did not do this extra searching, most imports or larger libraries would probably lead to broken executables. In terms of > create some sort of string searcher that will search for all instances of "import" strings in code/codes PyInstaller offers a [build-time dependency graph](https://pyinstaller.readthedocs.io/en/stable/when-things-go-wrong.html#build-time-dependency-graph), however they do note that this will show a significant amount of standard modules which can make the output huge. Looking at the output, you could then use the `--exclude-module` flag to ignore packages you do not want to be added. To get this output, I would recommend using PyInstaller directly using the generated command in auto-py-to-exe.
Author
Owner

@github-actions[bot] commented on GitHub (Nov 4, 2021):

This issue is stale because it has been open for 60 days with no activity. Remove stale label or comment on this issue or it will be closed in 5 days.

<!-- gh-comment-id:960344541 --> @github-actions[bot] commented on GitHub (Nov 4, 2021): This issue is stale because it has been open for 60 days with no activity. Remove stale label or comment on this issue or it will be closed in 5 days.
Author
Owner

@github-actions[bot] commented on GitHub (Nov 9, 2021):

Closing issue due to no activity in more than 60 days.

<!-- gh-comment-id:963709248 --> @github-actions[bot] commented on GitHub (Nov 9, 2021): Closing issue due to no activity in more than 60 days.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/auto-py-to-exe#176
No description provided.