Search python docs offline? - python

In python I can get some rudimentary documentation for any object using help(<object>). But to be able to search the documentation, I have to go online. This isn't really helpful if I'm somewhere where the internet isn't accessible.
In R, there is a handy double question mark feature (??<topic>) that allows me to search through the documentation of all installed libraries for any function that includes <topic> in its name or documentation string. Is there anything similar for python? Perhaps even just for loaded objects?

pydoc comes with python and can do searches but only in the synopsis lines of available modules. Quoting pydoc --help:
pydoc -k
Search for a keyword in the synopsis lines of all available modules.
Note that into pydoc you can perform searches using "/".

Look in the python folder in the folder: Doc. This folder has the entire downloaded documentation of the python docs from python.org. I know this is a VERY late answer, but it brings up an easy solution.

This was mentioned in the comments already: Zeal
is similar to Dash but for Windows/Linux. It uses the same sources as Dash. It's built using Qt and is available in the repositories for several distros, for Ubuntu there is a PPA. Download it here.
Zeal is a simple offline API documentation browser inspired by Dash (OS X app), available for Linux and Windows.
Quickly search documentation using Alt+Space (or customised) hotkey to display Zeal from any place in your workspace.
Search in multiple sets of documentation at once.
Don't be dependent on your internet connection.
Integrate Zeal with Emacs, Sublime Text, or Vim. See Usage » Editor plugins for details.
It is open source (GPL), development happens on GitHub. Zeal uses the same stylesheets/HTML as the online docs, so everything should look familiar.
An in-browser alternative is devdocs.io. You can access the website even if you are offline, provided that you've marked them for local offline storage. You'll need to enable the Python 2 docs, and then mark them for offline storage here. However, as a longtime user of the online Python docs, I find the custom stylesheet that DevDocs uses a bit distracting.

Just to add another option for offline access of python docs (mostly core):
I don't have access to a linux computer at the moment, but on windows, you can navigate to your_python_dist_folder/doc to find some help files. Particularly python275.chm for instance.
If there's no doc folder on your linux machine, you can download the file here and google for a linux chm viewer:
https://www.google.com/search?q=linux+chm+viewer
::Note:
Some distributions also include docs for other packages in there... might be worth a check. Other than that, help(module) usually returns good information.
Edit:
You could get something that might be a little closer to what you want by using pydoc. E.g. you are looking for something about sin in the math module:
import math
import pydoc
[i for i in dir(math) if 'sin' in pydoc.getdoc(getattr(math,i))]
This would return the methods whose docstrings include sin:
['acos', 'acosh', 'asin', 'asinh', 'cos', 'cosh', 'isinf', 'sin', 'sinh']
for which you then could run the help() function

In case your working in a Mac there is Dash, which allows you to download docsets and then explore/search offline. Despite its documentation functionality, Dash is also a Snippet Manager.

Windows Idle - F1 from shell window or editing window gets you a windows help file of all the docs. I think it's better than the online version - it's easier to find stuff.

Although there are certainly better documentations built into your computer than help() like windows idle, another option for some of the more common topics would just be to save some of the online documentation to your computer. For the modules you use a lot and want to access offline, you could just download a text file version of the official online python documentation, which is the best place to get documentation. (file > save page as > select .txt file format)

This may not have been available at the time the question asked and answered, but python.org now makes all the documentation available online as an archive of HTML files which can be navigated and searched offline: https://docs.python.org/2/download.html
(The link directs to docs for the latest version of 2.x, but you can choose 3.x and older 2.x versions from that page)

You should try ipython.
object_name? will print all sorts of details about any object,
including docstrings, function definition lines (for call arguments)
and constructor details for classes.
The magic commands %pdoc, %pdef, %psource and %pfile will respectively print the docstring, function definition line, full source code and the complete file for any object (when they can be found). If automagic is on (it is by default), you don’t need to type the ‘%’ explicitly.

Related

Documentation URL of os module

I'm trying to crack the URL format for Python's os module for use in PyCharm's documentation window.
My attempt so far:
https://docs.python.org/3/library/os.html#{element.qname}
but I'm having trouble displaying documentations such as:
https://docs.python.org/3/library/os.path.html#module-os.path
What's the right format?
Before addressing the URL hack, it should be mentioned that the deciding setting of how documentation is shown is the "Render external documentation for stdlib" setting. You can configure it by going to File > Settings > Python Integrated Tools > Docstrings > Render external documentation for stdlib as shown in the screenshot:
If you enable the "Render external documentation for stdlib" setting (and have internet access), the IDE will automatically retrieve standard library docs from https://docs.python.org/{python.version}/library/{module.name}.html#{element.qname}. The Python version is automatically determined from the Python interpreter configured for the Project, so that's the version of the documentation shown for the file you have opened in the editor.
See how this corresponds to the online documentation:
If you disable the "Render external documentation for stdlib" setting (or don't have internet access), the IDE will show the docstrings of its integrated stub files.
Having said that, the documentation tool window does not require configuring the URL for standard library modules (e.g. for the os, sys, etc...) contrary to how it's necessary for other libraries' External Documentation. In fact, there is no option in the IDE settings to change the address for standard library modules.
What's the right format?
The complete format would be:
https://docs.python.org/{python.version}/library/{module.name}.html#{element.qname}
crack the URL format for Python's os module for use in PyCharm's documentation window.
This can be done, but it is limited to specific modules. It can not be done for the whole standard library because the base Module Name field would have to be left empty and in that case the IDE will ignore the setting.
If you use the hack for a specific module, the IDE will show the docstrings in the documentation tool window (like in example 2) but if you click the external link it will open the browser in the address configured in the external documentation. See the screenshot:
So the hack has limited usefulness.
The hack can be used with offline docs if you download the Python HTML documentation (but it would still be limited to only showing documentation like in example 2). In that use case the correct way to write the URL would depend on OS/Shell/Browser, for Windows/CMD/Firefox you could use the below URL but there's no way to escape the hash # sign so the anchor won't work, but you'll be taken to the documentation page.
file:///C:/directory_name/library/{module.name}.html#{element.qname}

Is it possible to change the way PyCharm displays the OpenCV documentation?

PyCharm (PY-193.6911.25, macOS 10.15.4) doesn't correctly display the OpenCV documentation.
More concretely, this is the result.
As you can see, it's a mess. Is it possible to fix this? I installed OpenCV with pip.
After googling a lot I ended up thinking there is no easy solution but... there actually is!
What i did is:
Push CTRL Q
Scroll down to the trippledot and click open source.
Push CTRL+R(replace)
replace '. ' to ''
Now docstring looks like this:
Definately not perfect, but i think it looks a bit better.
Additionally i added this as external documentation:
https://opencv-python-tutroals.readthedocs.io/en/latest/search.html?q={element.name}&check_keywords=yes&area=default
So it brings up a cv2 'tutorial'...
In PyCharm 2020.1.1 professional edition with Python 3.7, the following warning is displayed for the cv2 docstring
You need configured Python 2 SDK to render Epydoc docstrings
Epydoc is a tool for generating API documentation for Python modules, based on their docstrings.
Pycharm can't render Epydoc docstrings
The suitable interpreter is looked up among those configured in the IDE (it has to be Python 2 since Epydoc package itself hasn't been ported to Python 3 yet). In other words, you need to set up it once so that it showed up on the list at Settings | Project: ... | Project Interpreter | Show All... -- it doesn't need to be actually used in any project. Is it true in your case?
The problem is that it's not really Epytext. OpenCV uses Doxygen for documentation that we don't support and also confuse with Epytext because of the similarity of tags. There is an open issue about it.
Doxygen is confused with Epydoc and displayed as free text (not preformatted)
I'm afraid this particular feature of PyCharm is not really extensible at the moment. Besides, displaying of documentation, injecting references to symbols inside it, completion of available tags and generation of documentation stubs -- everything is tied very closely to the fact that in Python code documentation is normally provided via designated string literals, not comments. The highest level API you can plug into to provide custom documentation source for Quick Documentation popup/tool window is com.intellij.lang.documentation.DocumentationProvider if you register yours before the default one with ID pythonDocumentationProvider. But it will cover only rendering, everything else will need to be written from scratch.
The official resolution is we don't support that

Using Eclipse PyDev's search function with external libraries

I find PyDev's search function incredibly useful and use it regularly to navigate around my projects. I've got my interpreters set up correctly so PyDev knows about the external libraries that my code uses, and even lets me follow references into the library modules. This is great, obviously, but I also want to be able to search the external libraries like I can search my own code.
There's a similar question pertaining to Java development here: How do I search Libraries in eclipse?
Is there anything out there for PyDev?
I use two different approaches to allow searching in my library code:
When I am using virtualenv, I keep all my code under myproject/src and add it and myproject/lib/python2.7/site-packages/ as pydev source folders. (Be sure to setup your python interpreter to myproject/bin/python as well)
In other cases, I use two different pydev projects. The first (myproject) includes my code. The second one is called myproject-lib and includes the libraries as it's source paths (.../site_packages). The first project references the second projects (and usually I keep both of them in one workspace). This works great with virtualenv, but I believe that you can actually create a pydev project in your system-wide python. Make sure you use the same python interpreter in both projects.
Now you can quickly and easily use Open Resource (CTRL+T) and the Globals Browser (CTRL+Shift+T) to lookup your libs.
I'm afraid PyDev doesn't support this yet. I created feature request for this at https://jira.appcelerator.org/browse/APSTUD-7405 Meanwhile you could link folders of external libraries to your project.

Can the LibreOffice LightProof grammar library be used externally?

LibreOffice 3.5 includes a grammar checker, called (or maybe based on) LightProof. From what I have read, LightProof seems to be a Python library that can be used to check for custom grammar rules. But I can not for the life of me find a project page for LightProof.
The closest I got was http://cgit.freedesktop.org/libreoffice/lightproof/tree/, which seems to be the code for the LibreOffice extension, not LightProof itself.
So is LightProof actually a library that can be implemented in other applications, or is it just a code word for a LibreOffice feature?
LightProof has been superseded by LanguageTool, the source of which is available on GitHub.
It's not possible yet, but: "we will be able to make a stand-alone version of Lightproof/Grammalecte as it won’t be necessary to use Hunspell anymore" - see Olivier R.'s post to the LibreOffice mailing list.

python-mode documentation for Emacs

I just installed the python-mode in Emacs and it seems to be working well. However, I could not find documentation for the package on the official site.
The package comes with a doc folder where I can see two files:
commands-python-mode.org
commands-python-mode.rst
Both files seem to be formatted for some external tool that displays the help text.
With this:
Is there a tool I can use to navigate this documentation?
Does python-mode have an online site with documentation? Any tutorials or good walk-throughs for python-mode for Emacs?
Start off with M-x describe-mode. This gives you an overview over the available key bindings. For each command use C-f name RET to see the built-in documentation. The .org file should be an org-mode file and easily readable with Emacs.
See also here
A cursory inspection of those two files and the code tells me that they're basically a listing of the docstrings found in pymacs.el and python-mode.el. That means you'll be able to access the relevant documentation through M-x apropos or C-h a and friends (specifically, search for ^py or ^pymacs to get a listing of the mode functions).
As a general rule, because elisp doesn't support namespaces, all functions/variables defined by a given mode will have a consistent prefix related to the name of the mode. That makes it fairly simple to search through the Emacs documentation.
If your a emacs user and haven't heard of org-mode before your in for treat.
Open the .org file in emacs and go to org-mode (METAxorg-mode), use TAB on the header lines. Header-lines starts with one or more *.
In addition to answers given: Try a walkthrough of the menu "Python", which appears at the head of window. It will display a short description of the commands or options.
WRT to beginnners, some introduction, examples of basic usage might be given still.
Filed a feature request:
https://bugs.launchpad.net/python-mode/+bug/1281970

Categories

Resources