How to install Python library from a repository?

I mostly understand apt-get and the Ubuntu Software Center, but one thing that I can't get at all is manually installing packages for which apt-get does not work. The file structure and layout of Ubuntu is really odd to me.

I am running Ubuntu 12.10 and have a Python library that I need to install. It's not one that you can get through apt-get or pip.

I have downloaded the zip file without any problem. As far I can tell I have to then extract it to usr/share/doc (at least this is where my other libraries store files to install for Python through apt-get).

I have no idea how to do this though since the GUI doesn't let me do anything that's not in my account folder. As far as I can tell, the usr is some completely disconnected file structure when it comes to a terminal (I can't simply back up a level from my user account to usr for instance).

What's the right way to install this Python library?


You should not put the file (or, actually, anything) into /usr... manually - this area is managed by Ubuntu's package manager.

I suppose you need the library because you want to write some Python script/program, right?

In this case you can just put it in the same folder as your program/script and do

from clientsubnetoption import ClientSubnetOption

Note that the library has a dependency on dnspython which, luckily, is in Ubuntu repositories so you can install it with

sudo apt-get install python-dnspython

(as a side-note: normally Python libraries are distributed as "python eggs" which are published in the central "store" called Python Package Index: https://pypi.python.org . From there they can be installed using special tools, such as easy_install, pip or zc.buildout. You can also create isolated Python environments using virtualenv and zc.buildout so there's absolutely no need to install even complex libraries system-wide)