Yesterday我问了一个关于同时使用Excel和Python的问题。找到了解决方案:使用xlwings
包。
然而,还有另一个问题 - 我无法将.py
文件保存为可执行文件(exe
)。
以下是我尝试保存的代码:
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)
我尝试使用cx_freezer
并使用以下代码制作了setup.py
文件:
from cx_Freeze import setup, Executable
setup(
name = "Uniform distribution generator",
version = "1.0",
description = "Uniform distribution generator",
executables = [Executable("doiterations.py")]
)
具有类似代码的此类setyp.py
文件正确地与其他模块一起使用。但是,这次我收到错误no file named sys
:
cx_Freeze.freezer.ConfigError: no file named sys (for module collections.sys)
我尝试使用PyInstaller
包并使用以下命令:
再次遇到错误:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc0 in position 7: ordinal not in range(128)
我搜索了Google和Stackoverflow,发现了一些有关此问题的评论,可能有助于找到解决方案:
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
我的Python版本是2.7。
请帮助解决问题并创建可运行的可执行文件!
答案 0 :(得分:2)
至少在cx_freeze的情况下,可以找到解释:https://bitbucket.org/anthony_tuininga/cx_freeze/issues/127/collectionssys-error
不幸的是Python Package Index没有提供包含必要更改的cx_freeze版本。安装Microsoft Visual C++ Compiler for Python 2.7后,可以安装新版本的cx_Freeze。可以使用 pip 命令从Python Package Index以外的其他位置安装python包,在这种情况下
pip install --upgrade https://bitbucket.org/anthony_tuininga/cx_freeze/get/tip.zip
这需要在开始菜单中找到的 Anaconda提示中完成。如果在安装Anaconda期间修改了PATH,则命令提示符就足够了。