29

I'm new to Python and am trying to install this module: http://www.catonmat.net/blog/python-library-for-google-search/

There is no setup.py in the directory, but there are these files:

 BeautifulSoup.py   browser.pyc    __init__.pyc  sponsoredlinks.py
 BeautifulSoup.pyc  googlesets.py  search.py     translate.py
 browser.py         __init__.py    search.pyc

Can someone please tell me how to setup or use this module?

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
osman
  • 1,590
  • 1
  • 14
  • 21
  • 6
    The simplest method: Put those files into a directory and add that directory's path to your PYTHONPATH: `import sys; sys.path.append("/path/to/google_search/lib")` – mechanical_meat Mar 15 '12 at 05:56
  • So really the main point of installing a Python module (with something like distutils) is so it's easily importable (and the fact that extension modules may need compilation on target machines)? – Yibo Yang Oct 10 '17 at 01:31

1 Answers1

40

The simplest way to begin using that code on your system is:

  1. put the files into a directory on your machine,
  2. add that directory's path to your PYTHONPATH

Step 2 can be accomplished from the Python REPL as follows:

import sys
sys.path.append("/home/username/google_search")

An example of how your filesystem would look:

home/
    username/
        google_search/
            BeautifulSoup.py
            browser.py
            googlesets.py
            search.py
            sponsoredlinks.py
            translate.py

Having done that, you can then import and use those modules:

>>> import search
>>> search.hey_look_we_are_calling_a_search_function()

Edit:
I should add that the above method does not permanently alter your PYTHONPATH.

This may be a good thing if you're just taking this code for a test drive.
If at some point you decide you want this code available to you at all times you will need to append an entry to your PYTHONPATH environment variable which can be found in your shell configuration file (e.g. .bashrc) or profile file (e.g. .profile).
To append to the PYTHONPATH environment variable you'll do something like:

export PYTHONPATH=$PYTHONPATH:$HOME/google_search
mechanical_meat
  • 163,903
  • 24
  • 228
  • 223
  • 2
    I see how this could be acceptable in 2012 when it was written but it is bad practice that should be discouraged in the age of actual dependency management. – Ezekiel Victor Feb 26 '18 at 21:07
  • 4
    Question Title was about how to install -- found this page via searching for help on this topic. This answer is about how to import. Not what the title is about. Not helpful. – sh37211 Apr 04 '21 at 21:32
  • 1
    Thanks for the comment @sh37211. This answer shows the simplest way to install not using setup.py I'm not sure why you don't think it's about installing. – mechanical_meat Apr 04 '21 at 22:37