1

I am trying to develop .exe file from my python script , but its size is more than 715MB , even i am using virtual environment for developing but still size is very big.

These libraries i am using in my script:

import numpy as np 
import pandas as pd
import os
import matplotlib.pyplot as plt
import configparser

Steps for developing .exe

1)pip install virtualenv  #install virtualenv

2)virtualenv name_env  #creat a virtualenv

3)pip install your packages in  new virtualenv

4)cmd and activate

5)cd to the dir of python script

4)pyinstaller -w -F  mainscript.py

Anyone can help to figure out where i am making mistake

normally this app should be 42MB or less than 50MB

but here size is 600MB+

Nickel
  • 580
  • 4
  • 19
  • I have used `pyi-archive_viewer` to see what is being included in the exe. Then use `excludes` in the `.spec` file to exclude the ones not needed from the exe. – John Anderson Jun 13 '20 at 03:06
  • I saved 400MB, see here: https://stackoverflow.com/questions/45722188/tutorial-for-installing-numpy-with-openblas-on-windows/67954011#67954011. I cannot answer because a moderator deleted it, even if the two questions are on a total different topic... – Thomas Jun 13 '21 at 09:57

1 Answers1

0

A large contribution is probably due to Qt (used by matplotlib) and MKL (used by numpy).

See for example:

Using OpenBlas instead of MKL can help.

To illustrate the difference, I built a simple example application with matplotlib/Qt and numpy using two different conda environments, on Windows 10: one using MKL, the other using openblas, as specified in the YAML files below.

The resulting executable sizes were:

  • mkl: 312 MB
  • openblas: 100 MB

The environments can be created using conda env create -f <filename>.

MKL environment (also see this discussion):

name: mkl
dependencies:
  - python=3.8
  - matplotlib
  - pyinstaller

Openblas environment (based on this and this):

name: openblas
dependencies:
  - python=3.8
  - conda-forge::blas=*=openblas
  - conda-forge::matplotlib
  - pyinstaller

Example application:

from matplotlib import pyplot as plt
import numpy as np

if __name__ == '__main__':
    x = np.arange(0, 10 * np.pi, 0.1)
    y = np.sin(x)
    dot_product = np.dot(y, y.T)  # just some matrix operation
    plt.plot(x, y)
    plt.title(dot_product)
    plt.show()

Built using: pyinstaller --clean -w -F main.py

djvg
  • 11,722
  • 5
  • 72
  • 103