我想将python程序转换为exe文件,但是随后我希望能够单击具有特定扩展名(例如.ftf)的文件,然后能够在python程序中打开文件并读取内容。我也在无法使用cmd但可以使用某些os模块命令的Windows 10计算机上,因此我进行了一些研究并且我仍然不清楚如何获取我要运行的扩展文件的文件名和路径与python文件,但我将python文件转换为exe,所以我如何打开扩展名文件的文件名和路径,然后将其内容读取为exe文件。因此,我尝试将我的porgram转换为EXE,并使用程序的exe版本运行扩展文件,但出现此错误:
Traceback (most recent call last):
File "D:\Users\Dextron\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\initscripts\__startup__.py"
, line 14, in run
module.run()
File "D:\Users\Dextron\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\initscripts\Console.py", li
ne 26, in run
exec(code, m.__dict__)
File "BashFile.py", line 18, in <module>
File "D:\Users\Dextron\AppData\Local\Programs\Python\Python36-32\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 2: character maps to <undefined>
我已使用cx_Freeze转换程序。这是我的设置文件
from cx_Freeze import setup, Executable
import os
base = None
executables = [Executable("BashFile.py", base=base)]
packages = ["os", "colorama", "datetime", "time", "socket", "random", "sys", "ctypes"]
options = {
'build_exe': {
'packages':packages,
},
}
os.environ['TCL_LIBRARY'] = r'D:\Users\26099\AppData\Local\Programs\Python\Python36-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'D:\Users\26099\AppData\Local\Programs\Python\Python36-32\tcl\tk8.6'
setup(
name = "BashFile",
options = options,
version = "1.0",
description = "A Simple Python program made to replace CMD",
executables = executables
)