2014-04-10 34 views
0

使用cx_Freeze時,我似乎無法使圖像正常工作。我試圖尋找另一種答案,發現here,但得到的錯誤:無法找到名爲文檔文件/目錄\影像\ robot_standing.fw.png如何在使用cx_Freeze時包含圖像?

這裏是我的setup.py文件:

from cx_Freeze import setup,Executable 

includefiles = ['Documents\images\robotStanding_sprite.fw.png', 'Documents\images\dirt_block.fw.png','Documents\images\grass_block.fw.png','Documents\images\spikes.fw.png','Documents\images\title_image.fw.png'] 
includes = [] 
excludes = [] 
packages = [] 

setup(
    name = 'Robot Game', 
    version = '0.1', 
    description = 'null', 
    options = {'build_exe': {'excludes':excludes,'packages':packages,'include_files':includefiles}}, 
    executables = [Executable('Robot Game.py')] 
) 

什麼我做錯了嗎?

+0

路徑需要與setup.py相關。 –

+0

@ThomasK他們是。文件是setup.py所在的文件夾,但我也嘗試了圖像。 – Alexdr5398

+0

您需要將\ \轉義爲\\或僅使用/ –

回答

0

您不能在文件名中使用.的圖像,因爲計算機不知道什麼是擴展名。 你應該叫'Documents\images\robotStanding_sprite.fw.png''Documents\images\robotStanding_sprite_fw.png'

1

我剛剛有同樣的問題。我分兩步解決它:

1)我使用了一個基於Brian的答案在How do I use cx_freeze?的setup.py腳本,並按照aquavitae在同一篇文章中描述的方式運行它。

2)我手動將所有圖像文件複製到可執行文件和其他輔助文件所在的build \ exe.win32-3.3目錄中。

注意:我在我的源代碼文件的名稱中使用了大寫字母,因爲我希望可執行文件具有大寫字母的名稱。它運行良好。