Reduce pyinstaller executable size

后端 未结 2 987
死守一世寂寞
死守一世寂寞 2020-12-19 10:59

I have only one line of code input() written in python and packed with pyinstaller with option --onefile. The exe file is 4577 kB which is almost 5

相关标签:
2条回答
  • 2020-12-19 11:24

    Ah, You are not creating the build in a separate virtual environment.

    Create a virtual environment just for build purpose and install the packages you need in this environment.

    in your cmd execute these to create a virtual enviornment

    python -m venv build_env

    cd build_env

    C:\build_env\Scripts\Activate

    you will see this >>(build_env) C:\build_env

    Install all the packages you need for your script, start with pyinstaller

    pip install pyinstaller

    Once you are all installed, build the exe as before. The exe built using the virtual environment will be faster and smaller in size!! For more details check https://python-forum.io/Thread-pyinstaller-exe-size

    0 讨论(0)
  • 2020-12-19 11:34

    The .exe file you create using pyinstaller includes the python interpreter and all modules included in your script.Maybe, the modules you are using have a big library themselves. You can however try using py2exe but it might not work for all projects.The other way to get it smaller is to use a compression program as like, compress the executable using UPX (have a look at this:http://htmlpreview.github.io/?https://github.com/pyinstaller/pyinstaller/blob/v2.0/doc/Manual.html#a-note-on-using-upx). You can also try excluding some items too but at the discretion that removing such items doesn't interfere with the functionality of your .exe.

    0 讨论(0)
提交回复
热议问题