Home » excel » excel – Error using cx_freeze and PyInstaller to make an .exe file in Python (which includes xlwings)

excel – Error using cx_freeze and PyInstaller to make an .exe file in Python (which includes xlwings)

Posted by: admin April 23, 2020 Leave a comment


Yesterday I asked a question about using Excel and Python simultaneously. The solution was found: using xlwings package.

However, there is another problem connected with that – I can not save my .py file as an executable file (exe).

Here is the code I try to save:


    import xlwings as xl
    import numpy
    import time

    wb = xl.Workbook.active()
    sheet = wb.active

    iter = input("How many iterations do you need? \n")
    i = 0
    cell1 = raw_input("Write a column where you need to iterate \n")
    cell2 = int(raw_input("Write a row where you need to iterate \n"))

    while True:
        i += 1
            if i <= iter:
                arg = numpy.random.uniform()
                xl.Range("%s%d" % (cell1, cell2)).value = arg



I tried to use cx_freezer and made a setup.py file with the following code:

        from cx_Freeze import setup, Executable

            name = "Uniform distribution generator",
            version = "1.0",
            description = "Uniform distribution generator",
            executables = [Executable("doiterations.py")]

Such setyp.py files with the similar code properly worked with other modules. However, this time I got an error no file named sys:

    cx_Freeze.freezer.ConfigError: no file named sys (for module collections.sys)

enter image description here

I tried to use PyInstaller package with the following command:

enter image description here

and again faced an error:

    UnicodeDecodeError: 'ascii' codec can't decode byte 0xc0 in position 7: ordinal not in range(128)

enter image description here

I searched through Google and Stackoverflow and found some comments on this problem that may help to find the solution:


cx_freeze fails to create exe with pandas library
cx-freeze error on build
Traceback from CX_Freeze doesn't make sense

My version of Python is 2.7.

Please, help to solve the problem and create a working executable file!

How to&Answers:

At least in the case of cx_freeze an explanation can be found: https://bitbucket.org/anthony_tuininga/cx_freeze/issues/127/collectionssys-error

Unfortunately Python Package Index does not provide a version of cx_freeze that includes the necessary changes. A new version of cx_Freeze can be installed after Microsoft Visual C++ Compiler for Python 2.7 has been installed. It is possible to install python packages from other locations than Python Package Index with pip command, in this case

pip install --upgrade https://bitbucket.org/anthony_tuininga/cx_freeze/get/tip.zip

This needs to be done in Anaconda prompt that should be found from the Start menu. command prompt suffices if the PATH has been modified during the installation of Anaconda.