views:

54

answers:

1

I'm having trouble with setuptools in a larger project where a python package has to be "constructed" from several debian packages (each containing a subpackage of the "main" package). Thus we decided to install the files manully instead of using "setup.py install", but we are unsure of the location to use. We first used a directory in /usr/share that we already use for other stuff we install. This works fine except for the fact that we have to mess around with PYTHONPATH before starting any application.

Is there any place that is in the default sys.path where we could install packages instead? I was thinking about /usr/lib/python2.6/dist-packages (which is where the files should end up when you use setuptools as well, shouldnt they?), but I'm kind of reluctant of writing to a place like this with custom install scripts... Also, what if Ubuntu switches to 2.7, do we have to move as well then? Any "best practice" how to do something like this? This whole site-packages/dist-packages concept is so under-documented :(

+1  A: 

It is kind of hard to say where you need to install your Python packages taking into account that, in fact, you can install it anywhere you want. The best place in my opinion is to put them into /usr/local/share/YOURPACKAGENAME in case it was not installed by apt-get (aptitude etc...). In either case, you have to create a small wrapper around you python script(s) which inserts a path(s) to where your package(s) are located into "sys.path" variable. For example, "yum" for Ubuntu puts its files to "/usr/share/yum-cli" by default and "/usr/bin/yum" script contains the following lines:

#!/usr/bin/python

...

sys.path.insert(0, '/usr/share/yum-cli')
try:
    import yummain
    yummain.user_main(sys.argv[1:], exit_code=True)
except KeyboardInterrupt, e:
    ...

Alternatively, you have to set PYTHONPATH environment variable. There is nothing wrong with that.

Vlad Lazarenko
"There is nothing wrong with that." No, it isnt. But it's boring and error-prone ;) We also use sys.path modifications now :)
Chris089