【问题标题】:How do I see the Python doc on Linux?如何在 Linux 上查看 Python 文档?
【发布时间】:2012-03-22 06:56:22
【问题描述】:

在Windows中,Python有一个chm类型的文档,阅读起来非常方便。 但是在Linux中,有没有什么文档可以让我看的?

【问题讨论】:

  • 你不能只搜索Python documentation website吗?此外,Google 非常擅长查找正确的文档。
  • 致 Joachim Pileborg.sorry,这里的网络很糟糕,所以我需要离线文档。
  • 有一天我忘记了如何启动 PyDoc localhost 服务器。我开始在 Python 文档网站上搜索,但并没有走得太远。所以我求助于 Stack Exchange,这里的一个答案给了我我所追求的。所以也许我们应该保留这个问题。

标签: python linux doc


【解决方案1】:

在线文档

最简单的方法是使用 Google 获取在线文档。没有一个地方可以找到所有模块的所有文档。但是,一些常见的有:

如果您需要离线文档,还有其他几种可能:

下载它

您可以下载 HTML 或 PDF 格式的文档:https://docs.python.org/3/download.html

当您有一个网络服务器正在运行时,您可以使用 HTML 版本并像过去一样通过浏览器访问它。 HTML 站点看起来就像您习惯的那样。甚至搜索也可以离线工作,因为它是用 JavaScript 实现的。

PyDoc

像 Debian 这样的一些发行版提供了一个python-doc 包。您可以通过以下方式访问它 pydoc -p [some port number] 或通过pydoc -g。这将创建一个本地 Web 服务器。然后你就可以打开浏览器看看了:

控制台:帮助(...)

Python 交互式控制台有一个内置的help(...) 系统。您可以在没有参数的情况下调用它:

$ python
Python 2.7.5+ (default, Feb 27 2014, 19:37:08) 
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> help()

Welcome to Python 2.7!  This is the online help utility.

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/2.7/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics".  Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".

help> 

或者你可以用你想知道的参数来调用它。这可以是任何东西(模块、类、函数、对象……)。它看起来像这样:

>>> a = {'b':'c'}
>>> help(a)
Help on dict object:

class dict(object)
 |  dict() -> new empty dictionary
 |  dict(mapping) -> new dictionary initialized from a mapping object's
 |      (key, value) pairs
 |  dict(iterable) -> new dictionary initialized as if via:
 |      d = {}
 |      for k, v in iterable:
 |          d[k] = v
 |  dict(**kwargs) -> new dictionary initialized with the name=value pairs
 |      in the keyword argument list.  For example:  dict(one=1, two=2)
 |  
 |  Methods defined here:
 |  
 |  __cmp__(...)
 |      x.__cmp__(y) <==> cmp(x,y)
 |  
 |  __contains__(...)
 |      D.__contains__(k) -> True if D has a key k, else False
 |  
 |  __delitem__(...)
 |      x.__delitem__(y) <==> del x[y]
 |  
 |  __eq__(...)
 |      x.__eq__(y) <==> x==y
 |  
 |  __ge__(...)
 |      x.__ge__(y) <==> x>=y
 |  
 |  __getattribute__(...)
 |      x.__getattribute__('name') <==> x.name
 |  
 |  __getitem__(...)
 |      x.__getitem__(y) <==> x[y]
 |  
 |  __gt__(...)
: (scroll)

【讨论】:

  • pydoc 也可以不带标志使用,在这种情况下,输出进入less(类似于man)。例如尝试pydoc os.path
【解决方案2】:

【讨论】:

    【解决方案3】:

    如果你使用 Fedora 发行版,那么yum install python-docs。其他发行版可能会提供类似的软件包。

    【讨论】:

    • 同上 debian/ubuntu: sudo apt-get install python-doc; firefox /usr/share/doc/python-doc/html/index.html
    【解决方案4】:

    您还可以安装 Ipython 以在交互模式下检查模块/对象。
    例如,您可以在 ipython 中执行此操作:

    import pygame  
    pygame.draw.line?
    

    然后你会得到结果文档:

    pygame.draw.line(Surface, color, start_pos, end_pos, width=1): return Rect
    画直线段

    在 ipython 中你可以使用 tab 编译,它有助于检查某些东西。

    【讨论】:

      【解决方案5】:

      最好的方法是阅读 Python shell 中内置的文档。

      $ python
      Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53) 
      [GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
      Type "help", "copyright", "credits" or "license" for more information.
      >>> help()
      
      Welcome to Python 2.7!  This is the online help utility.
      
      If this is your first time using Python, you should definitely check out
      the tutorial on the Internet at http://docs.python.org/tutorial/.
      
      Enter the name of any module, keyword, or topic to get help on writing
      Python programs and using Python modules.  To quit this help utility and
      return to the interpreter, just type "quit".
      
      To get a list of available modules, keywords, or topics, type "modules",
      "keywords", or "topics".  Each module also comes with a one-line summary
      of what it does; to list the modules whose summaries contain a given word
      such as "spam", type "modules spam".
      
      help> 
      

      【讨论】:

      • 内置帮助的难点在于没有帮助功能(我可以找到),如果您不知道自己在寻找什么,就很难浏览帮助。 R 有一个非常好的??topic 搜索方法,可以查看所有可用的库。 python有没有类似的东西?
      【解决方案6】:

      我认为最好的选择是使用DevDocs

      • 加上离线
      • 此外,它还有一个桌面应用程序

      【讨论】:

        【解决方案7】:

        对于python

        pydoc -g
        python -m pydoc -g
        

        3.3以后的python

        pydoc -b
        python -m pydoc -b
        

        【讨论】:

          【解决方案8】:
          • 系统 Ubuntu 18.04

          要查看 Python 的离线文档,

          1. 安装 python3-docsudo apt install python3-doc 。文件安装在/usr/share/doc/python3-doc/html
          2. 用网络浏览器打开/usr/share/doc/python3-doc/html/index.html

          文档如官方文档网站所示:https://docs.python.org/3/

          【讨论】:

            【解决方案9】:

            既然您在互联网上,请利用online python docs

            【讨论】:

            • 既然这没有回答问题,而且只是一个链接,应该是评论。
            • 当然它回答了这个问题,他想阅读 linux 上的文档并且那里有文档。你要我说明他需要使用浏览器吗?
            • 对不起,是我的错,我没有说完整。我需要一个离线文档。
            • 您假设我们大多数人都在线。在安全设施和其他互联网连接为零的地方有许多开发人员。无处不在,是的。无处不在,没有。
            猜你喜欢
            • 1970-01-01
            • 2016-04-08
            • 1970-01-01
            • 1970-01-01
            • 2012-05-20
            • 2016-07-13
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多