Search code examples
pythoncx-freeze

Change folder structure in Python cx_Freeze project


I made a Python application, and I wanted to construct exe file to simplify sharing among Windows users. I used:

  • Python 3.6.1
  • cx_Freeze module 5.0.2

I got an exe file, but the final structure made me cry:

  • executable file
  • zip archive with Python 3.6
  • 3 dlls (python, sqlite, vcruntime)
  • 21 folders
  • 10 pyd files

In my opinion, it is not convinient for users and I would like to move folders and pyd files into separate folder or archive (it would be better). Does anybody know to do it? Current build.py:

from cx_Freeze import setup, Executable

setup(
    name = 'myapp',
    version = '0.1',
    executables = [Executable(
        script='__main__.py',
        targetName='myapp.exe',
        icon='myapp.ico'
    )]
)

What options should I add to my setup function? Is it possible to do in current versions of Python and cx_Freeze? Or should I patch cx_Freeze like this?


Solution

  • My problem has been almost solved in the version 5.1. There were only 5 items in the build directory:

    • lib folder
    • exe file
    • 3 dlls (python36, sqlite, vcruntime)

    It was ok for me, but exe file did not work. There was an error ModuleNotFoundError: no module named 'codecs'.

    The answer has been found here. There is an error in the current version (5.1 at the moment), but the patch has been already done. Unfortunately, new version (5.1.1) is not in the PyPI.

    Nevertheless solution is pretty simple: to build cx_Freeze from the sources. It is mentioned here. (Visual Studio is needed, I used 2013 one). Or you can just wait for a while, I hope new version will be in the PyPI soon.