簡體   English   中英

轉換為.exe的Python文件(.py)無法執行(Python 3.4 + cx_Freeze)

[英]Python file (.py) converted to .exe fails to execute (Python 3.4 + cx_Freeze)

我轉換了簡單的“ Hello world ... press enter”腳本,並使用cx_Freeze模塊將其轉換為.exe。 運行正常。 當我嘗試轉換littlebit復雜腳本並運行它時,出現了問題。 它本身運行的腳本完美,但是.exe無法正常工作。

症狀:.exe啟動,命令行閃爍一次,但沒有任何反應。

腳本結構:僅使用os模塊和sys模塊。

腳本功能:基本上讀寫.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”。

我想通了。 我的腳本文件名就是問題。 在轉換期間,cx_freeze創建了模塊庫.zip,但是腳本模塊的位置受名稱的影響。 名稱中的圓點成為.zip文件的子目錄,因此main的路徑錯誤並且找不到。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM