Windows 7 - 从命令提示符使用pydoc

4 投票
5 回答
9597 浏览
提问于 2025-04-16 06:52

好吧,我现在有点怀疑自己能不能用电脑。这不是我想象中作为第一次在Stack Overflow发帖会问的问题,但我还是来问了。

我开始学习Zed的新书《Learn Python the Hard Way》,因为我想在停了10年后重新开始编程,而Python一直是我想学的语言。这本书真的让我很有共鸣。不过,我在命令行使用pydoc时遇到了一个大问题。我已经把c:/python26里的所有目录都加到了系统路径里,所以我可以在命令行中顺利执行pydoc,无论当前工作目录是什么,但它就是不接受任何参数。我输入什么都没用,只能看到pydoc的标准输出,告诉我可以接受哪些参数。

有没有什么想法?顺便说一下,我是按照Zed的建议安装了ActivePython。

C:\Users\Chevee>pydoc file
pydoc - the Python documentation tool

pydoc.py <name> ...
    Show text documentation on something.  <name> may be the name of a
    Python keyword, topic, function, module, or package, or a dotted
    reference to a class or function within a module or module in a
    package.  If <name> contains a '\', it is used as the path to a
    Python source file to document. If name is 'keywords', 'topics',
    or 'modules', a listing of these things is displayed.

pydoc.py -k <keyword>
    Search for a keyword in the synopsis lines of all available modules.

pydoc.py -p <port>
    Start an HTTP server on the given port on the local machine.

pydoc.py -g
    Pop up a graphical interface for finding and serving documentation.

pydoc.py -w <name> ...
    Write out the HTML documentation for a module to a file in the current
    directory.  If <name> contains a '\', it is treated as a filename; if
    it names a directory, documentation is written for all the contents.


C:\Users\Chevee>

编辑:新信息,pydoc在PowerShell中工作得很好。作为一个Linux用户,我也不知道为什么我还在尝试使用cmd——但我还是想搞清楚pydoc和cmd之间的问题。

编辑2:更多新信息。在cmd中...

c:\>python c:/python26/lib/pydoc.py file

...一切都很好。只用pydoc在PowerShell中就能顺利运行,我根本不用担心当前工作目录、扩展名或路径。

5 个回答

0

根据你第二次编辑的内容,你的路径中可能有多个 pydoc.py 文件,而且可能是先找到的那个是“错误”的版本,这样在启动时它就没有正确的环境来运行了。

2

当你在Windows的命令提示符下输入一个文件名时,cmd会查看Windows注册表来找默认的文件关联,然后用那个程序来打开文件。所以如果Inkscape的安装程序把.py文件和它自己版本的python关联起来了,cmd可能会优先运行那个程序,而完全忽略PATH环境变量。想了解更多,可以看看这个问题

7

在Windows的Powershell中,你可以使用这个命令:python -m pydoc

下面是一些例子:

python -m pydoc open

python -m pydoc raw_input

python -m pydoc argv

撰写回答