我正在试图弄清楚如何通过distutils安装我的程序。我的最终目标是为ubuntu用户制作.deb安装程序。主要问题是让“一键式”启动器文件起作用。
我的程序使用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 = "mad.programs@gmail.com",
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()
因此,配方轨道安装在根目录之外,并将其权限更改为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 :(得分: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 /。从这个位置我没有权限写入该文件。所以我想这里的解决方案是将数据文件安装到主目录。我仍然在研究这个问题的跨平台解决方案。