简体   繁体   English

如何在没有 setup.py 的情况下安装 Python 模块?

[英]How to install a Python module without a setup.py?

I'm new to Python and am trying to install this module: http://www.catonmat.net/blog/python-library-for-google-search/我是 Python 新手,正在尝试安装此模块: http : //www.catonmat.net/blog/python-library-for-google-search/

There is no setup.py in the directory, but there are these files:目录下没有setup.py,但是有这些文件:

 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. put the files into a directory on your machine, 将文件放入计算机上的目录中,
  2. add that directory's path to your PYTHONPATH 将该目录的路径添加到PYTHONPATH

Step 2 can be accomplished from the Python REPL as follows: 第2步可以从Python REPL完成,如下所示:

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. 我应该补充说,上述方法不会永久改变你的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 (eg .bashrc ) or profile file (eg .profile ). 如果在某些时候您决定在任何时候都希望此代码可用,则需要在PYTHONPATH环境变量中附加一个条目,该条目可以在shell配置文件(例如.bashrc )或配置文件(例如.profile )中找到。 。
To append to the PYTHONPATH environment variable you'll do something like: 要附加到PYTHONPATH环境变量,您将执行以下操作:

export PYTHONPATH=$PYTHONPATH:$HOME/google_search

Why don't you write the setup script yourself and commit it to upstream? 为什么不自己编写安装脚本并将其提交到上游? - that way everybody wins . - 这样每个人都赢了

For further references, do a SO search 如需进一步参考,请进行SO搜索

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM