Installing 3rd party Python modules on an Ubuntu Linux machine?

Viewed 64845

I'm guessing my question is pretty basic, but after 15-20 minutes on Google and YouTube, I am still a little fuzzy. I am relatively new to both Linux and Python, so I am having some difficulty comprehending the file system tree (coming from Windows).

From what I've found digging around the directories in Ubuntu (which is version 12.04, I believe, which I am running in VBox), I have ID'd the following two directories related to Python:

  1. /usr/local/lib/python2.7 which contains these two subdirectories:

    dist-packages
    site-packages

    both of which do not show anything when I type "ls" to get a list of the files therein, but show ". .." when I type "ls -a".

  2. /usr/lib/python2.7 which has no site-packages directory but does have a dist-packages directory that contains many files and subdirectories.

So if I want to install a 3rd party Python module, like, say, Mechanize, in which one of the above directories (and which subdirectory), am I supposed to install it in?

Furthermore, I am unclear on the steps to take even after I know where to install it; so far, I have the following planned:

  1. Download the tar.gz (or whatever kind of file the module comes in) from whatever site or server has it
  2. Direct the file to be unzipped in the appropriate subdirectory (one of the 2 listed above)
  3. Test to make sure it works via import mechanize in interactive mode.

Lastly, if I want to replace step number 1 above with a terminal command (something like sudo apt-get), what command would that be, i.e., what command via the terminal would equate to clicking on a download link from a browser to download the desired file?

5 Answers
Related