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)
I tried to use PyInstaller
package with the following command:
and again faced an error:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc0 in position 7: ordinal not in range(128)
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!
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.
Tags: excel, file, pythonpython