How to install a Python module without a setup.py?

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

Leave a Comment