我转换了简单的“Hello world ... press enter”脚本,并使用cx_Freeze模块将其转换为.exe。它运行良好。当我试图转换littlebit复杂脚本并运行它时,我遇到了问题。它自己运行完美的脚本,但.exe不起作用。转换为.exe的Python文件(.py)无法执行(Python 3.4 + cx_Freeze)
症状:.exe启动,命令行闪烁一次,没有任何反应。
脚本结构:仅使用os模块和sys模块。
脚本funktions:basicly读取和写入.txt文件
脚本流程:1. 变化CWD 2.打开.TXT 3.读取.TXT到列表 4.在改变细胞列表,其中某些字符串位于 5.文件 6.关闭文件 7.等待用户投放到结束写入列表回(sys.stdin.readline())
我无法弄清楚什么是错的。
import os
import sys
#change cwd
os.chdir('S:/user_name/')
#locate the line where "sertain_string: False" is
file = open('Test_dir/test.txt', 'r+')
lines= file.readlines()
file.close()
x = 0
while(lines[x] != "certain_string: False\n"):
x = x + 1
continue
else:
print("certain_string is on line", + x)
print("\n")
#Read the lines to the list
file = open('Test_dir/test.txt', 'r+')
lines = fiel.readlines()
file.close()
print("\n")
#Change the cell where "certain_string: false" is to "certain_string: True"
lines[x] = 'certain_string: True\n'
print("\n")
#write the list back to the file
file = open('Test_dir/test.txt', 'w+')
file.writelines(lines)
file.close()
print("Done... press enter:")
r = sys.stdin.readline()
我从命令行运行.exe文件。
错误报告:
cf_freeze console.py line 26:
Code = importer.get_code(moduleName)
zipimport.ZipImportError: Can't find module 'client_v.0.02__main__'.
我不明白这一点。它试图从.zip文件中找到client_v.0.02__main__模块,该文件是在.py到.exe转换过程中创建的模块库。 我的.py文件名是“Client_v.0.02”。
请显示您的代码。 – 2015-03-13 14:11:25
尝试使用命令行执行它。这样,在程序退出后,您仍然可以看到最终的堆栈跟踪/错误报告或任何其他标准输出。 – Maciek 2015-03-13 14:12:42