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

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

问题描述

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

目录下没有setup.py,但是有这些文件:

 BeautifulSoup.py browser.pyc __init__.pycsponsorlinks.pyBeautifulSoup.pyc googlesets.py search.py​​ translate.pybrowser.py __init__.py search.py​​c

谁能告诉我如何设置或使用这个模块?

谢谢!

解决方案

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

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

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

导入系统sys.path.append("/home/username/google_search")

文件系统外观示例:

home/用户名/谷歌搜索/BeautifulSoup.py浏览器.pygooglesets.py搜索.py赞助链接.py翻译.py

完成后,您可以导入和使用这些模块:

<预><代码>>>>进口搜索>>>search.hey_look_we_are_calling_a_search_function()


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

如果您只是将此代码用于试驾,这可能是一件好事.
如果在某些时候您决定希望此代码始终可供您使用,您需要将一个条目附加到您的 PYTHONPATH 环境变量中,该条目可以在您的 shell 配置文件(例如 .bashrc)中找到或配置文件(例如 .profile).
要附加到 PYTHONPATH 环境变量,您将执行以下操作:

export PYTHONPATH=$PYTHONPATH:$HOME/google_search

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?

Thanks!

解决方案

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

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

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