想使用distutils安装我的python应用程序吗;一键式;启动程序文件
我正试图找出如何通过distutils安装我的程序。我的最终目标是为ubuntu用户制作一个.deb安装程序。主要问题是如何让“一键式”启动程序文件正常工作 我的程序使用pygtk和sqlite3作为gui和数据库。我使用glade帮助构建gui,因此我的程序绑定到几个glade文件中。然后我还将数据存储在.sqlite3文件中。这是我到目前为止的包结构想使用distutils安装我的python应用程序吗;一键式;启动程序文件,python,linux,distutils,setup.py,Python,Linux,Distutils,Setup.py,我正试图找出如何通过distutils安装我的程序。我的最终目标是为ubuntu用户制作一个.deb安装程序。主要问题是如何让“一键式”启动程序文件正常工作 我的程序使用pygtk和sqlite3作为gui和数据库。我使用glade帮助构建gui,因此我的程序绑定到几个glade文件中。然后我还将数据存储在.sqlite3文件中。这是我到目前为止的包结构 root/ |_ src/ | |_ RTcore/ | |_ data/
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""",
)
setup(
packages = ["RTcore"],
package_dir = {"src": "RTcore"},
package_data = {"RTcore": ["Rui/*"]},
data_files = [("Data", ["data.sqlite3"])],
)
我的“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)
然后挂断,无法找到它们
如果我将cd插入程序的根目录并运行“recipetrack”,程序将正常运行。但我希望能够从系统上的任何位置运行“recipetrack”
我认为问题在于setup.py文件和package_数据行。我尝试过改用data_文件,但这不起作用,因为它在安装过程中挂起,无法找到数据文件
我希望这已经很清楚了,有人可以帮忙
谢谢,
海伯
已更改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""",
)
setup(
packages = ["RTcore"],
package_dir = {"src": "RTcore"},
package_data = {"RTcore": ["Rui/*"]},
data_files = [("Data", ["data.sqlite3"])],
)
但是现在安装程序没有安装我的data.sqlite3文件。我已经解决了这里的主要问题。总的问题是我的数据文件没有被包括在内。在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/。在此位置,我没有写入文件的权限。因此,我想这里的解决方案是将数据文件安装到主目录。我仍在研究解决此问题的跨平台解决方案。python应用程序运行的环境是什么?你能记录对os.getcwd或os.environ的调用并查看返回的结果吗?你看过“entry_points”关键字吗?@albert我需要一些关于这些命令的帮助。我试着用一份打印的声明把它们加进去,但结果很奇怪。我正试图让程序在Ubuntu中运行。一旦我记下来了,我就做一个.deb和一个.exe。@GufyMike我还没有看“入口点”。我会在distutils文档中查找它。更新:我已经读了一些关于它的书,我不确定这是我正在寻找的方向。我需要我的脚本来加载数据文件。入口点有没有办法做到这一点?这似乎是从类等模块加载代码的一种方式。没问题,我们是来帮忙的!此处介绍python中的操作系统模块:。它是一个独立于操作系统的库,允许您使用python操作文件和系统环境。例如,os.getcwd将获取您当前的工作目录。我这样问是因为我不止一次被我的应用程序环境所困扰,尤其是在制作独立的可执行文件或安装程序时。