如何在没有setup.py的情况下安装Python模块? [英] How to install Python module without setup.py?

查看:652
本文介绍了如何在没有setup.py的情况下安装Python模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Python的新手,正在尝试安装此模块: http://www.catonmat.net/blog/python-library-for-google-search/

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

目录中没有setup.py,但是有以下文件:

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?

谢谢!

推荐答案

在系统上开始使用该代码的最简单方法是:

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

  1. 将文件放入您计算机上的目录
  2. 将该目录的路径添加到您的PYTHONPATH

步骤2可以通过Python REPL完成,如下所示:

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

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

文件系统外观示例:

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()


我应该补充一点,上述方法不会永久更改您的PYTHONPATH.


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

如果您只是将此代码用于测试驱动器,这可能是一件好事.
如果您决定在任何时候都希望此代码可用,则需要在PYTHONPATH环境变量后面附加一个条目,该条目可以在外壳程序配置文件(例如.bashrc)或配置文件(例如).
要附加到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

这篇关于如何在没有setup.py的情况下安装Python模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆