Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 652
osman Avatar asked Mar 15 '12 05:03

osman


People also ask

How do I use python modules without installing?

If you are not able to install modules on a machine(due to not having enough permissions), you could use either virtualenv or save the module files in another directory and use the following code to allow Python to search for modules in the given module: >>> import os, sys >>> file_path = 'AdditionalModules/' >>> sys.

Does pip need setup py?

As a first step, pip needs to get metadata about a package (name, version, dependencies, and more). It collects this by calling setup.py egg_info . The egg_info command generates the metadata for the package, which pip can then consume and proceed to gather all the dependencies of the package.

How do I install Python modules locally?

Installing Python Packages with Setup.py To install a package that includes a setup.py file, open a command or terminal window and: cd into the root directory where setup.py is located. Enter: python setup.py install.


1 Answers

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 
like image 194
mechanical_meat Avatar answered Sep 27 '22 19:09

mechanical_meat