2012-07-27 67 views
4

我和一個團隊的朋友們創造了這個遊戲,我現在想在linux下運行,Pygame打破Pydev之外。

我們開發它使用python 2.7和pygame的使用的Aptana Studio和代碼窗口通過有運行時,工作充分。

當它下載到Linux它不會加載說它找不到文件。然後我嘗試通過Windows中的CMD運行它,並且出現相同的錯誤。

錯誤至今

Traceback (most recent call last): 
    File "/home/user/Desktop/Raspberroids/mainmenu.py", line 144, in <module> 
    showMenu() 
    File "/home/user/Desktop/Raspberroids/mainmenu.py", line 107, in showMenu 
    menu.init(['Start','About','Quit'], surface) 
    File "/home/user/Desktop/Raspberroids/mainmenu.py", line 52, in init 
    self.create_strukture()   
    File "/home/user/Desktop/Raspberroids/mainmenu.py", line 73, in create_strukture 
    self.font = pygame.font.Font(self.font_path, self.fontsize) 
IOError: unable to read font filename 

和源是: https://github.com/ryanteck/RasPiThon/tree/master/Raspberroids/Source%20Code

發生在兩個2.7和2.6

誰能幫助?

回答

5

您的字體路徑data/coders_crux/coders_crux.ttf是相對的。

當您從源目錄之外的其他目錄開始遊戲時,pygame找不到字體。


一個簡單的解決方法是以下行添加到您的腳本的頂部(mainmenu.py):

import os 
os.chdir(os.path.dirname(os.path.realpath(__file__))) 

os.path.realpath(\__file__)將得到的路徑,你的腳本,並與os.chdiros.path.dirname您將當前工作目錄更改爲腳本的目錄。

這樣,你使用的相對路徑就可以工作。

+0

謝謝:)現在工作:D – 2012-07-27 13:34:35

+0

謝謝你這個照明的答案。 – invert 2013-06-15 19:06:41

1

PyDev設置你的程序的工作目錄和PYTHONPATH變量。它還可以將控制檯編碼設置爲與OS默認設置不同的內容。

在創建Font對象之前添加print self.font_path聲明並查看路徑是否正常。如果是相對路徑,您也可以使用os.path.abspath(詳情請參閱os.path文檔)以更好地理解正在發生的事情。