2011-03-19 28 views
0

我想弄清楚如何使我的程序可以通過distutils安裝。我的最終目標是爲ubuntu用戶製作一個.deb安裝程序。主要問題是獲得「一鍵式」啓動文件的工作。想要使用distutils來安裝我的python應用程序和一個「一鍵式」啓動文件

我的程序使用pygtk和sqlite3作爲gui和數據庫。我用glade來建立我的gui,所以我的程序連接到幾個glade文件。然後我還將數據存儲在.sqlite3文件中。這裏是我封裝結構至今...

root/ 
    |_ src/ 
    |  |_ RTcore/ 
    |    |_ data/ 
    |    |  |_ data.sqlite3 
    |    |_ ui/ 
    |    | |_ main.glade 
    |    | |_ addRecipe.glade 
    |    |_ __init__.py 
    |    |_ main.py #this is where I store the meat of my program 
    |    |_ module.py #recipetrack is supposed to run this module which ties into the main.py 
    |_ setup.py 
    |_ manifest.in 
    |_ README 
    |_ recipetrack #this is my launcher script 

這是我目前的setup.py文件...

#!/usr/bin/env python 

from distutils.core import setup 
files = ["Data/*", "ui/*"] 
setup(
    name = "RecipeTrack", 
    version = "0.6", 
    description = "Store cooking recipes and make shopping lists", 
    author = "Heber Madsen", 
    author_email = "[email protected]", 
    url = "none at this time", 
    packages = ["RTcore", "RTcore/Data","RTcore/ui"], 
    package_data = {"RTcore": files}, 
    scripts = ["recipetrack"], 
    long_description = """Something long and descriptive""", 
    ) 

我 「recipetrack」 腳本代碼...

#!/usr/bin/env python #it appears that if I don't add this then following 2 lines won't work. 
#the guide I was following did not use that first line which I found odd. 
import RTcore.module 

RTcore.module.start() 

因此,recipetrack get安裝在根目錄之外,並將其權限更改爲755,以便系統上的所有用戶都可以啓動該文件。一旦啓動recipetrack應該啓動根文件夾中的模塊,然後從那裏啓動main.py,一切都應該正常運行。但事實並非如此。 「recipetrack」確實啓動模塊,然後導入main.py類,但此時程序嘗試加載數據文件(即data.sqlite3,main.glad或addRecipe.glad。) ,然後掛起無法定位他們。

如果我進入程序的根目錄並運行「recipetrack」程序正常運行。但我希望能夠從系統的任何位置運行「recipetrack」。

我相信問題在於package.data行的setup.py文件。我試過用data_files代替,但這不起作用,它在安裝過程中掛起無法找到數據文件。

我希望這已經很清楚,有人在那裏可以提供幫助。

感謝, 希伯

改變setup.py文件...

setup(
     packages = ["RTcore"], 
     package_dir = {"src": "RTcore"}, 
     package_data = {"RTcore": ["Rui/*"]}, 
     data_files = [("Data", ["data.sqlite3"])], 
    ) 

但現在安裝不安裝我data.sqlite3文件。

+0

您的python應用程序運行的環境是什麼?你可以記錄一個調用os.getcwd或os。環境,看看回報是什麼? – 2011-03-19 02:30:38

+0

你看過'entry_points'關鍵字嗎? – 2011-03-19 04:08:41

+0

@albert我需要這些命令的一點幫助。我試圖用打印語句添加它們,但結果很奇怪。我試圖讓程序在Ubuntu中運行。一旦我把它弄下來,然後我會做一個.deb和一個.exe。 – shload 2011-03-19 04:28:55

回答

0

我解決了我在這裏遇到的主要問題。總而言之,我的數據文件並未包含在內。在setup.py文件中,我需要將以下調用設置爲...

setup(
    packages = ["RTcore"], 
    package_dir = {"RTcore": "src/RTcore"}, 
    package_data = {"RTcore": ["ui/*"]}, 
    data_files = [("Data", ["/full/path/data.sqlite3"])], 
) 

以這種方式使用setup.py讓一切安裝正確。要克服的下一個障礙是在任何用戶運行該程序時調用數據文件,並從cmd行中系統的任何位置調用數據文件。我用下面的命令爲這個...

dir_path = os.path.dirname(os.path.abspath(__file__)) 
os.chdir(dir_path) 

的最後一個問題我留下的是確定如何去設置全局權限的data.sqlite3文件。在Ubuntu 10.10 distutils安裝我的數據文件到/ usr/local/Data /。從這個位置我沒有寫入文件的權限。所以我想這裏的解決方案是將數據文件安裝到主目錄。我仍在研究這個問題的跨平臺解決方案。

相關問題