I converted simple "Hello world ... press enter" script, and converted it to .exe using cx_Freeze module. It runs fine. When i tried to convert littlebit complex script and run it, I got problem. The script it self runs perfect but .exe wouldn't work.
symptom: .exe starts, command line flashes once and nothing happens.
Scripts structure: Uses only os module and sys module.
Scripts funktions: basicly reads and writes a .txt file
script flow: 1. changes cwd 2. opens .txt 3. reads .txt to a list 4. changes the cell in a list where certain string is located 5. writes the list back in the file 6. closes the file 7. waits to user in put to end (sys.stdin.readline())
I cant figure out what is wrong.
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()
I run .exe file from command line.
Error report:
cf_freeze console.py line 26:
Code = importer.get_code(moduleName)
zipimport.ZipImportError: Can't find module 'client_v.0.02__main__'.
I don't understand this. It tries to find client_v.0.02__main__ module from the .zip file, which is module library created during .py to .exe convertion. My .py file name is "Client_v.0.02".
I figured out. My scripts file name was the issue. During conversion, cx_freeze made module library .zip, but the location of the scripts main module was affected by the name. A dot in the name made a subdirectory to library .zip file so the path to main was wrong and couldn't be found.