使用cx_freeze和PyInstaller在Python中创build.exe文件时出错(其中包括xlwings)

昨天我问了一个关于同时使用Excel和Python的问题。 解决scheme被发现:使用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并使用以下代码创buildsetup.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) 

在这里输入图像说明

我通过谷歌和Stackoverflowsearch,发现这个问题,可能有助于find解决scheme的一些意见:

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无法创build与pandas库exe文件 cx冻结生成 从CX_Freeze traceback没有任何意义

我的Python版本是2.7。

请帮忙解决这个问题并创build一个可执行文件!

至less在cx_freeze的情况下可以find一个解释: https ://bitbucket.org/anthony_tuininga/cx_freeze/issues/127/collectionssys-error

不幸的是, Python Package Index没有提供包含必要更改的cx_freeze版本。 在安装了Microsoft Visual C ++编译器for Python 2.7后,可以安装新版本的cx_Freeze。 在这种情况下,可以使用pip命令从Python Package Index以外的位置安装Python包

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

这需要在“ 启动”菜单中find的Anaconda提示符中完成。 如果在安装Anaconda期间修改了PATH,命令提示符就足够了。

Interesting Posts