转换为.exe的Python文件(.py)无法执行(Python 3.4 + cx_Freeze)

时间:2015-03-13 14:04:10

标签: python python-3.x cmd cx-freeze

我转换了简单的“Hello world ...按Enter”脚本,并使用cx_Freeze模块将其转换为.exe。它运行正常。当我试图转换littlebit复杂脚本并运行它时,我遇到了问题。它自己运行的脚本完美但.exe不起作用。

症状:.exe启动,命令行闪烁一次,没有任何反应。

脚本结构:仅使用os模块和sys模块。

脚本funktions:基本上读取和写入.txt文件

脚本流程: 改变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”。

1 个答案:

答案 0 :(得分:0)

我发现了。我的脚本文件名是个问题。在转换期间,cx_freeze创建了模块库.zip,但脚本 main 模块的位置受名称影响。名称中的一个点构成了库.zip文件的子目录,因此 main 的路径错误,无法找到。

相关问题