3

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:

doiterations.py

    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
            else:
                break

        wb.save()
        print("Done!")

        time.sleep(2)

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

        from cx_Freeze import setup, Executable

        setup(
            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:

https://mborgerson.com/creating-an-executable-from-a-python-script http://www.dreamincode.net/forums/topic/192592-making-an-exe-file-with-pyinstaller/

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!

Community
  • 1
  • 1
Alex
  • 265
  • 2
  • 15
  • Please post text as [formatted text](https://stackoverflow.com/editing-help), not images. – zondo Jun 18 '16 at 11:14
  • @zondo If you tell me how to copy text from a control panel of Windows (cmd), I will do it with a great pleasure. – Alex Jun 18 '16 at 11:35
  • @shivsn Could you clarify me, please, where should I exactly put your code in? A full algorithm would also be helpful. – Alex Jun 18 '16 at 11:37
  • @shivsn It does not work either with `setup.py` or with `doiterations.py`. How did you use it? – Alex Jun 18 '16 at 12:10
  • You could try moving your files to another location, like `c:\temp\test` i.e. a path that does include other characters than ascii. – J.J. Hakala Jun 18 '16 at 12:32
  • @shivsn Did not work either. Returns the same error. – Alex Jun 18 '16 at 12:46
  • @Alex what about pyinstaller? – J.J. Hakala Jun 18 '16 at 12:46
  • @J.J.Hakala Unfortunately, it did not work with `cx_freezer`. He returns the same error as I mentioned before (`ConfigError`). It also did not work with `PyInstaller` (returns the same `UnicodeDecodeError`). – Alex Jun 18 '16 at 12:57
  • try setting unicode in your program like `import sys`, `reload(sys)`,`sys.setdefaultencoding('utf8')` add these lines to `doiterations.py` and try. – shivsn Jun 18 '16 at 13:28
  • @shivsn Unfortunately, it did not work either both with cx_freeze and pyinstaller. – Alex Jun 18 '16 at 21:53

1 Answers1

2

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.

J.J. Hakala
  • 6,136
  • 6
  • 27
  • 61
  • Again does not work. However, I might make mistakes. Please, check me. 1. During Step 6 I wrote `pip install --upgrade cx_freeze` as it did not allow me to write without `cx_freeze`. 2. During Step 4 I started an usual Windows command prompt (cmd). Maybe I should have started another one? – Alex Jun 18 '16 at 22:16