Search code examples
pythondependency-managementcx-freezevirtual-environment

How does cx_Freeze detect the virtual environments/dependencies?


I just succeeded to build .exe file with cx_Freeze.
The only problem is that the size of the build folder(incl. .exe, .ui, libraries) is too large(1.02GB) in spite of a few functions. And I found that the folder called numpy_mkl takes up a large proportion(745MB) of the build folder.

Because Anaconda is installed on my PC and I know that numpy installed in Anaconda environment accompanies mkl, I created .venv(independent virtual environment with virtualenv) and installed numpy with pip install numpy in this virtual environment.

However it seems cx_Freeze consider not only the libraries from active virtual environment(.venv) but also from the libraries installed by Anaconda.

This is the part of the log from execution of python setup.py build.

copying C:\Users\anaconda3\Library\bin\mkl_avx.1.dll -> C:\Users\Desktop\Python\P3-pid\build\exe.win-amd64-3.9\lib\numpy_mkl\mkl_avx.1.dll
copying C:\Users\anaconda3\Library\bin\mkl_avx2.1.dll -> C:\Users\Desktop\Python\P3-pid\build\exe.win-amd64-3.9\lib\numpy_mkl\mkl_avx2.1.dll

Is there anyone who knows how cx_Freeze detect the dependencies?
Or any solution to this problem is welcome!


Solution

  • Can you build with using pycharm terminal as pycharm creates venv in a sepeate path and you can see the difference.Also can you try with out anaconda environment in pycharm. if nothing works you can do like this in your setup.py file.

    build_options = {'packages': ['flask', 'numpy'], 'excludes': ['sqlite3', 'idna', 'pandas', 'Tkinter','tcl','pytz','numpy-mkl'],

    you can exclude the numpy-mkl package