want to use distutils to install my python app with a "one-click" launcher file
I'm trying to figure out how to make my program installable via distutils. My end goal is to make a .deb installer for ubuntu users. The main issue is getting a "one-click" launcher file to work.
My program uses pygtk and sqlite3 for the gui and database. I've used glade to help build my gui and so my program ties into a couple of glade files. and then I also store data in a .sqlite3 file. Here is my package structure so far...
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
this is my current setup.py file...
#!/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""",
)
the code for my "recipetrack" script is...
#!/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()
So the recipetrack get's installed outside of the root directory and has it's permissions changed to 755, so that all users on the system can launch the file. Once started recipetrack should start module which is in the root folder and then starts the main.py from there everything should run as normal. But it doesn't. "recipetrack" does start module which then imports main.py class but it's at this point the program tries to load data files (ie. data.sqlite3, main.glad, or addRecipe.glad.) and then just hangs unable to locate them.
If I cd into the root of the program and run "recipetrack" the program runs normally. But I want to be able to run "recipetrack" from any location on the system.
I believe the problem lies in the setup.py file with the package_data line. I have tried using data_files instead but this doesn't work it hangs during install unable to locate the data files.
I hope this has been clear, and someone out there can help.
Thanks, Heber
changed setup.py file...
setup(
packages = ["RTcore"],
package_dir = {"src": "RTcore"},
package_data = {"RTcore": ["Rui/*"]},
data_files = [("Data", ["data.sqlite3"])],
)
开发者_开发百科
But now setup isn't installing my data.sqlite3 file.
I've solved the main issue I had here. The over all problem was that my data files weren't being included. In the setup.py file I needed to have the following calls set like...
setup(
packages = ["RTcore"],
package_dir = {"RTcore": "src/RTcore"},
package_data = {"RTcore": ["ui/*"]},
data_files = [("Data", ["/full/path/data.sqlite3"])],
)
using the setup.py in this fashion got everything installed properly. the next hurdle to overcome was to call up the data files when any user runs the program, and from any location on the system in the cmd line. I used the following commands for this...
dir_path = os.path.dirname(os.path.abspath(__file__))
os.chdir(dir_path)
The last issue I'm left with is determining how to go about setting global permission for the data.sqlite3 file. In Ubuntu 10.10 distutils installs my data file to /usr/local/Data/. From this location I don't have permissions to write to the file. So I guess the solution here is to install the data file to the home directory. I'm still looking into a cross platform solution to this problem.
精彩评论